0

I want to update the 'Name' value from array of object (myArr[ ]) using Arr_id.

mydb:{
     "_id" : ObjectId("5eb2b06d626fc539172013f8"),
     "is_deleted" : false,
     "email" : "rajnish@dresma.com",
     "myArr": [
         {"Arr_id":"5eb2b06d626fc539172013f7",
          "Name":"Aman"
          },
         {"Arr_id":"5eb2b06d626fc539172001k9",
          "Name":"Ram"
          },
         {"Arr_id":"5eb2b06d626fc539172013k4",
          "Name":"Piyush"
          }
        ]
     }
Kumar
  • 436
  • 1
  • 4
  • 16

1 Answers1

0
You can update in nested objects using $ positional operator.
here , Id is the id you want to update the value of name.
db.collection.update(
    { "myArr.Arr_id": Id }, 
    { "$set": { "myArr.$.Name": "SHYam" } }

)

Ayushi Gupta
  • 91
  • 1
  • 2
  • 9