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
![](https://secure.gravatar.com/avatar/29dab31861c63518c7ec182bfe507cfb?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)