0

I tried to update the array inside the embedded document field. but it is not working how to achieve this scenario.

data_Collection

{
    "id":101,
    "review_ratings":[
       {
           id:102,
           name:"hari"
       },{
           id:103,
           name:"mani"
       }
    ]
}

How to update id 103 name field

1

2 Answers 2

0

You should use positional operators

db.test.update({"id":101, "review_ratings.id": 103},
               {$set: {"review_ratings.$.name":"mohit"}});
Sign up to request clarification or add additional context in comments.

Comments

0
You can use aggregate function for searching and can use find and update method like:-

test.aggregate(
                [
                  { $match: {} },
                  {$project: {
                    review_ratings: {
                      $filter: {
                        input: '$review_ratings',
                        as: 'review_ratings',
                        cond: { $wq: [ '$$review_ratings.id', '103' ] }
                      }
                    }
                   }
                  }

                ],
                (err, res) => {

                });

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.