How To Update Mongodb Array Values
I have a document stored in mongodb like this 'Fiction' : [ { 'SNo': '1', 'authorName' : 'Enid Blyton', 'bookNam
Solution 1:
Use the $ positional
operator in your update as this identifies the element in an array to update without explicitly specifying the its position in the array:
db.fiction.update({"Fiction.SNo":"1"},{$set:{"Fiction.$.Amount":135}})
Solution 2:
The $
operator is used to iterate through the array list while updating.
Your query would be :
db.Fiction.update({"Fiction.SNo":"1"},{$set:{"Fiction.$.Amount" : 135}})
Post a Comment for "How To Update Mongodb Array Values"