Organizational Research By

Surprising Reserch Topic

how to change all the array elements in a mongodb document to a certain value


how to change all the array elements in a mongodb document to a certain value  using -'javascript,node.js,mongodb,mongodb-query'

Suppose I have the following document

{
   _id: ObjectId("5234cc89687ea597eabee675"),
   code: "xyz",
   tags: [ "school", "book", "bag", "headphone", "appliance" ],
   qty: [
          { size: "S", num: 10, color: "blue" },
          { size: "M", num: 45, color: "blue" },
          { size: "L", num: 100, color: "green" }
        ]
}

{
   _id: ObjectId("5234cc8a687ea597eabee676"),
   code: "abc",
   tags: [ "appliance", "school", "book" ],
   qty: [
          { size: "6", num: 100, color: "green" },
          { size: "6", num: 50, color: "blue" },
          { size: "8", num: 100, color: "brown" }
        ]
}

{
   _id: ObjectId("5234ccb7687ea597eabee677"),
   code: "efg",
   tags: [ "school", "book" ],
   qty: [
          { size: "S", num: 10, color: "blue" },
          { size: "M", num: 100, color: "blue" },
          { size: "L", num: 100, color: "green" }
        ]
}


I want to change the num of all the elements in the document having the code "efg" to 0. How do I do that ? Should I use a loop with the positional operator ?
    
asked Sep 22, 2015 by balvant maurya
0 votes
5 views



Related Hot Questions



Government Jobs Opening


...