0

Que:Increment the quantity by 10, for item_id "IJK2"

{
    item: "IJK2",
    details: { model: "14Q2", manufacturer: "M5 Corporation" },
    stock: [ { size: "S", qty: 5 }, { size: "L", qty: 1 } ],
    category: "houseware"
}

My query is but i am getting an error

db.inventory.update({item:IJK2},{$inc:{stock.qty:10}})
TomG
  • 2,409
  • 4
  • 23
  • 40
Gaurav verma
  • 679
  • 6
  • 12

1 Answers1

0

In mongo 3.6 you can use the positional-all operator:

db.test.updateOne(
    {
        item: 'IJK2'
    },
    {
        $inc: {
            'stock.$[].qty': 10
        }
    }
)
TomG
  • 2,409
  • 4
  • 23
  • 40