How to push new items to an array inside of an object

后端 未结 2 892
时光取名叫无心
时光取名叫无心 2021-01-22 03:45

My JSON currently looks like this:

{
    \"_id\" : 393,
    \"item\" : 34,
    \"comments\" : [
        {
            \"name\" : \"kevin\",
            \"message         


        
2条回答
  •  粉色の甜心
    2021-01-22 04:26

    Using $elemMatch and $ operator you can update your documents check below query :

    db.collectionName.update({"_id":393,"comments":{"$elemMatch":{"name":"kevin"}}},
                             {"$push":{"comments.$.messages":39}})
    

提交回复
热议问题