MongoDB: update dictionary in document

南楼画角 提交于 2019-12-05 04:36:28

from mongoDb website look at "Set Fields in Embedded Documents"

To specify a <field> in an embedded document or in an array, use dot notation.
For the document matching the criteria _id equal to 100, the following
operation updates the make field in the details document:


db.products.update(
{ _id: 100 },
{ $set: { "details.make": "zzz" } })

in your case

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