相关疑难解决方法(0)

MongoDB:更新子文档

我有这个系列:

[{ "_id" : 7,
   "category" : "Festival",
   "comments" : [
        {
                "_id" : ObjectId("4da4e7d1590295d4eb81c0c7"),
                "usr" : "Mila",
                "txt" : "This is a comment",
                "date" : "4/12/11"
        }
    ]
}]
Run Code Online (Sandbox Code Playgroud)

我想要的是在这样的注释中插入一个新字段:

[{ "_id" : 7,
   "category" : "Festival",
   "comments" : [
        {
                "_id" : ObjectId("4da4e7d1590295d4eb81c0c7"),
                "usr" : "Mila",
                "txt" : "This is a comment",
                "date" : "4/12/11",
                "type": "abc"  // find the parent doc with id=7 & insert this inside comments
        }
    ]
}]
Run Code Online (Sandbox Code Playgroud)

如何在comments子文档中插入?

mongodb

44
推荐指数
1
解决办法
5万
查看次数

标签 统计

mongodb ×1