I have a small script that finds an element in array, and I want to add another field to this element. this is my script:
db.myCollection.find({)}).forEach((doc)=> {
doc.someArray.forEach((someArrayObj)=> {
if (someArrayObj.someField != undefined) {
var arrayElement = doc.someOtherArray.find(ob => ob.id == someArrayObj.id)
// i want to add a new field to this arrayElement
}
});
});
how can I add another field and value to this element?
if the element is for example:
{
a : 1
b: 2
}
I want to update it to be:
{
a : 1
b: 2
c: true
}
how can I accomplish this?