I have a User document, with an array of Notes (objects) inside it. I'm trying to set a new field (_id) on all items in the array. But It's not touching anything. This is my current code, am I missing anything?
db.users.update(
{'notes.added': '2018-10-22 04:42:45.336Z'},
{'$set': {'notes.$._id': new ObjectId()}},
{multi: true}
);
Also I'm targeting all notes, where added equals that date, is it possible to target ALL notes without specifying a parameter?
_idis the field mongoDB uses and it is auto added for every element in the array so there is no need to se tit manually.