$inc¶
-
$inc¶ The
$incoperator increments a value of a field by a specified amount. If the field does not exist,$incsets the field to the specified amount.$incaccepts positive and negative incremental amounts.The following example increments the value of
field1by the value ofamountfor the first matching document in the collection wherefieldequalsvalue:To update all matching documents in the collection, specify
multi:truein theupdate()method:The first
update()operation increments the value of theagefield by1for all documents in the collection that have anagefield equal to20. The second operation increments the value of theagefield by2for all documents in the collection with thenamefield equal to"John".