0

There is a way to concat more updates? For example I would like to change more values in the same element. So having this...

{
    cc: [
          { user_id: "1", hasSeen:true}
         ,{ user_id: "2", hasSeen:false}
         ,{ user_id: "3", hasSeen:false}

    ]
    ,conversation: [{
        user_id: "1",
        text: "message by 1, to 2and3"
    }]
}

...I would like to push a new conversation object and also change all the hasSeen values.

For do the first point, no problem, I just push only a new conversation object. And it works...

    ...update(
        { _id : _param.conversation_id }
        ,{ $push:{ conversation:{user_id:"2",text:"message by 2, to 1,3"} }}
    )
    .exec(function(err, numAffected, rawResponse) {
    });

But I would like also to change the three "hasSeen" values in the same time. is it possible? Can I do it with one query? or i should split it in two queries?

ps: I use mongoose.

4

1 回答 1

0

目前,位置运算符(我认为您在这里需要)不能以这样一种方式工作,即您可以进行一种条件更新,通过这种方式您可以遍历$incs 或$sets 的列表来更改这些子文档值。

有一个 JIRA 可以帮助您:https ://jira.mongodb.org/browse/SERVER-6566?page=com.atlassian.jira.plugin.system.issuetabpanels:changehistory-tabpanel但它是在“我们不确定的功能”下提交。

目前最好将其拆分。

于 2013-08-22T11:11:29.367 回答