0

Here is my collection:

{
    "_id" : ObjectId("58d32e3c8726e31b00004ac9"), 
    "buyer" : "zul@buyer1001", 
    "sellers" : [
        {
            "seller" : "razi@seller1001", 
            "items" : [
                {
                    "item_name" : "Mizuno Wave Lightning Z3", 
                    "brand" : "Mizuno",
                    "status" : "Disabled"
                },
                {
                    "item_name" : "Mizuno Wave Fang SS", 
                    "brand" : "Mizuno",
                    "status" : "Disabled"
                }
            ]
         }
    ]
}

How do I update all items status to "Enable" ?

chridam
  • 100,957
  • 23
  • 236
  • 235
  • Hi Adfued Fufu Fued, and welcome to Stack Overflow. Can you show what you've tried so far, and point out where it is working or not working? You shouldn't ask a question without showing some evidence that you've already tried to find out the answer for yourself. – Vince Bowdren Mar 23 '17 at 10:37

1 Answers1

0

For Mongo shell you can use this command,

db.collection.find({}).forEach(function(doc) {
doc.sellers.forEach(function(list) {
    list.items.forEach(function(object) {
        object.status = "Enabled";
    });
});
db.collection.save(doc);
});
Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
radhakrishnan
  • 1,399
  • 1
  • 14
  • 20