$push equivalent for map in mongo

六眼飞鱼酱① 提交于 2019-12-05 18:23:53

Dot notation with the $set operator is how you address individual elements.

Take the following document:

{
    "_id": 1,
    "map": {
        "field2": 1
    }

}

In order to add "field3" to the map you update like this:

db.collection.update({ "_id": 1 }, { "$set": { "map.field3": 2 } })

So now your document looks like this:

{
    "_id": 1,
    "map": {
        "field2": 1,
        "field3": 2
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!