0
{
"_id" : "x2Yp4hnK8mvHhdYn4",
"fileid" : "kcSMLyR4wZc2gMADq",
"filepath" : "E:/sample/file4.txt",
"filecontent" : [ 
    {
        "path" : "file4.txt",
        "flag" : 0,
        "randno" : "UbEsfTKin9"
    }, 
    {
        "path" : "copy.txt",
        "flag" : 0,
        "randno" : "fcMQU7wk3c"
    }, 
    {
        "path" : "about.txt",
        "flag" : 0,
        "randno" : "kBdKtHu8qQ"
    }
]

}

I want to update flag value to 1 for all the filecontent.flag using _id and filecontent.flag : 0 . I used filecontent.$.flag operator which update first matching. But I want to update all the flag objects.

jamuna
  • 71
  • 1
  • 11
  • filecontent.find({ "_id":contentid }) .forEach(function (doc) { doc.filecontent.forEach(function (event) { if (event.flag === 1) { event.flag = 0 ; console.log(event); } }); filecontent.save(doc); }); – jamuna Sep 20 '17 at 06:51
  • the above code does not work – jamuna Sep 20 '17 at 06:51

0 Answers0