Update field in exact element array in MongoDB

后端 未结 3 849
执念已碎
执念已碎 2020-11-22 07:19

I have a document structured like this:

{
    _id:\"43434\",
    heroes : [
        { nickname : \"test\",  items : [\"\", \"\", \"\"] },
        { nickname          


        
3条回答
  •  迷失自我
    2020-11-22 07:54

    db.collection.update(
    {
    heroes:{$elemMatch:{ "nickname" : "test"}}},
     {
         $push: {
            'heroes.$.items': {
               $each: ["new_value" ],
               $position: 1
            }
         }
       }
    
    )
    

提交回复
热议问题