Possibility to have _id field with new ObjectId added to each array element automatically
Hi,
I thought it would be a good idea to have the option to have an array automatically add an _id field with new ObjectId per element if its an array of object.
In our use cases, we mostly update/delete items by their _id.
In the case where we want to do a bulk $push or something similar, there are currently no way of generating the _id's except looping through our array and generating the ids beforehand which is not ideal.
Another option would be to be able to use an update operator to generate a new ObjectId.
For example:
updateMany({},{
$push: {
"myArray": {
someField: "someValue",
_id: "$ObjectId" // this would generate a unique object id per element that is inserted in this update operation.
}
}
});
1
vote
Kheang Hok
shared this idea