Mongodb Increment value inside nested array

To update an element in an array field, you can use the positional $ operator

For example, the following js increments c from 3 to 4 for _id 341445:

db.collection.update({a:1, "b._id":341445} , {$inc:{"b.$.c":1}})

Leave a Comment