Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Compass
Created by Guest
Created on Sep 6, 2022

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. } } }); ```
  • Attach files