hey guys,
i am having a doubt,i want to update all the objects in an array with a unique id. i tried this,but all the objects are getting same id,but i want all objects with unique id’s(Note:only having one document in collection)
my code: collection.update({“Finra Rules.Part.Subparts”:{"$type":“array”}},{“set”:{“Finra Rules.Part.[].id”:ObjectId()}})
In my opinion you either need to run this: MongoDB update many or to break up the processing - e.g. get each item, update it and you are done, so something like:
db.find({the array id}). fetch().forEach(function (element) {
//process things here
element.field = 'new stuff';
})
// or something like that
If I am bad at explaining - sorry - I am relatively new to coding.
Hope it helps anyway…
Have a nice day!