Node.js 基于$或筛选器在文档中更新

Node.js 基于$或筛选器在文档中更新,node.js,mongodb,Node.js,Mongodb,我收集了一些像 { "_id": ObjectId("565ff61d454231a81753866a"), "tripMembers" : [ { "username" : "akshay.kumar@gmail.com", "contact" : null, "userId" : "1234999", "accept" : 2, "_id" : Objec

我收集了一些像

{
"_id": ObjectId("565ff61d454231a81753866a"),
"tripMembers" : [ 
        {
            "username" : "akshay.kumar@gmail.com",
            "contact" : null,
            "userId" : "1234999",
            "accept" : 2,
            "_id" : ObjectId("565ff61d454231a817538664")
        }, 
        {
            "username" : "akshay@gmail.co",
            "contact" : null,
            "userId" : "",
            "accept" : 0,
            "_id" : ObjectId("565ff61d454231a817538665")
        }]
}
我想更新数组中对象的键。我正在使用以下查询,但它不起作用

db.trips.update({
    $or :[
        {"tripMembers.username" : "akshay.kumar@gmail.com"},
       {"tripMembers.contact": "1234999" }]
    },
    {"_id" :ObjectId("565ff61d454231a81753866a")},
    {$set : {"tripMembers.accept" :1}
})
这给了我一个错误位置运算符没有从查询中找到所需的匹配项。未扩展的更新:tripMembers.$.accept

如果我在
$或
操作符中尝试相同的查询,那么它的工作状态与

db.trips.update({
    $or :[
        {"tripMembers.username" : "akshay.kumar@gmail.com"}  
    },
    {"_id" :ObjectId("565ff61d454231a81753866a")},
    {$set : {"tripMembers.accept" :1}
})
不知道,我错在哪里。有什么值得注意的帮助吗。

应该是:

b.trips.update({
    $and:
        [{$or :[
            {"tripMembers.username" : "akshay.kumar@gmail.com"}  
        ]},
        {"_id" :ObjectId("565ff61d454231a81753866a")}]
    },
    {$set : {"tripMembers.accept" :1}})

关闭]支架的位置不正确

db.trips.update({
    $or :[
        {"tripMembers.username" : "akshay.kumar@gmail.com"},
       {"tripMembers.contact": "1234999" }] <<--- no closing brace here
    },
    {"_id" :ObjectId("565ff61d454231a81753866a")}, << -- your update clause as David points out. This will wipe out all subdocs and leave only _id. urp!
    {$set : {"tripMembers.accept" :1} << -- not executed. irrelevant
})
根据你的数据进一步分析。一个小的场地

       "contact" : null,
        "userId" : "1234999",

很可能是$10或。。。{“tripMembers.用户id”:“1234999”},

您试图用
{“\u id”:ObjectId(“565ff61d454231a81753866a”)}
做什么?看起来更新时出现语法错误,并且从那里开始。您的“$set”似乎是第三个参数,应该是第二个参数。不幸的是,我不能。请修改您的帖子和固定括号
       "contact" : null,
        "userId" : "1234999",