更新对象数组内的标志

时间:2014-09-25 10:50:37

标签: node.js mongodb

我有这个文件:

{
    "_id" : ObjectId("540d881d475d68010693e340"),
    "notes" : [ 
        {
            "owner" : null,
            "creation" : 1411641315424,
            "text" : "test rec",
            "action" : "0",
            "recipients" : [ 
                {
                    "username" : "root",
                    "read" : false
                }, 
                {
                    "username" : "zivolof",
                    "read" : false
                }
            ]
        },
        {
            "owner" : null,
            "creation" : 1411641315424,
            "text" : "test rec",
            "action" : "0",
            "recipients" : [ 
                {
                    "username" : "root",
                    "read" : false
                }, 
                {
                    "username" : "zivolof",
                    "read" : false
                }
            ]
        }
    ]
}

我通过此查询找到它:

{
    "_id": id, 
    "notes.recipients": {
         $elemMatch: {
            username: username, 
            read: false
        }
    }
}

然后我需要将整个文档的read标志更新为true。我该怎么办?

0 个答案:

没有答案