Update Arrays Element in MongoDB: Updating single element in Array data type in MongoDB using the shell.

I have 2 documents in MongoDB like below

now I want to update the grades value of 100 to 1000. Below is the Query for updating a single element in Array.

In the above Query, dummy_collection is the Collection name and it will replace 100 to 1000  from all documents in Collection

if we want to Update element in a nested array

Now I want to update the 75 in grade array below will be the query

In the above Query, by using dotted Notation  we are mentioning the MongoDB to update the array which is under allGrades where grade array value is 75 to 80

Also Read: How to Rename/Modify JSON field keys in Mongo Document

Update Arrays Element in MongoDB

Leave a Reply

Your email address will not be published. Required fields are marked *