小编Ami*_*gal的帖子

在mongodb中的嵌套数组文档中更新第n个文档

我需要更新Mongo DB中另一个文档中的数组中的文档


    {
            "_id" : ObjectId("51cff693d342704b5047e6d8"),
            "author" : "test",
            "body" : "sdfkj dsfhk asdfjad ",
            "comments" : [
                    {
                            "author" : "test",
                            "body" : "sdfkjdj\r\nasdjgkfdfj",
                            "email" : "test@tes.com"
                    },
                    {
                            "author" : "hola",
                            "body" : "sdfl\r\nhola \r\nwork here"
                    }
            ],
            "date" : ISODate("2013-06-30T09:12:51.629Z"),
            "permalink" : "jaiho",
            "tags" : [
                    "jaiho"
            ],
            "title" : "JAiHo"
    }


Q1) Update email of 0th element of comments array
db.posts.update({"permalink" : "haha"},{$set:{"comments.0.email":1}})
This doesn't throw any exception but doesn't update anything as well
Q2) Add …

arrays updates mongodb

4
推荐指数
2
解决办法
4094
查看次数

标签 统计

arrays ×1

mongodb ×1

updates ×1