如果存在MongoDB文档,如何将字段添加到另一个字段?

时间:2018-08-21 11:46:35

标签: mongodb

我有类似以下文件的收藏新闻:

{
    "newsAttachments" : [ 
        {
            "type" : "file",
            "title" : "bknk",
            "date" : NumberLong(1534839736092)
        }, 
        {
            "type" : "file",
            "title" : "jbk.n .n",
            "date" : NumberLong(1534839736092)
        }
    ],
    "_displayString" : "23654165464",
    "__type" : "news"
}

我需要向新闻集中存在的secetLevel中的每个节点添加newsAttachments

如下所示,我有一个查询,但是当newsAttachments是数组时却无法唤醒

db.news.update({'newsAttachment': {$exists : true}}, {$set: {'newsAttachment.secretLevel': 1}}, {multi: true})

0 个答案:

没有答案