【发布时间】:2015-01-25 10:18:06
【问题描述】:
我在“用户”集合中有以下文档
{
"_id" : "388179687996974",
"matches" : [
{
"userId" : "1495728740672094",
"choice" : false,
"dates" : [],
"dateId" : null
},
{
"userId" : "385516561596016",
"choice" : true,
"dates" : [],
"dateId" : "2014-11-26_385516561596016_388179687996974"
},
{
"userId" : "253752728167114",
"choice" : false,
"dates" : [],
"dateId" : null
},
{
"userId" : "365296866955687",
"choice" : null,
"dates" : [
"2014-11-26"
],
"dateId" : null
}
],
"playDates" : [
"2014-11-26"
]
}
我有以下问题
db.users.find({
"_id":{"$ne":"385516561596016"},
"playDates":{"$in":["2014-11-26"]},
"matches":{"$elemMatch":{
"userId":"385516561596016",
"dates":{"$nin":["2014-11-26"]}}}})
它返回上面的文档。
我正在尝试使用位置运算符更新文档,如下所示:
db.users.update({
"_id":{"$ne":"385516561596016"},
"playDates":{"$in":["2014-11-26"]},
"matches":{"$elemMatch":{"userId":"385516561596016",
"dates":{"$nin":["2014-11-26"]}}}},
{"$push":{"matches.$.dates":"2014-11-26"}})
它没有将 2014-11-26 放入用户 ID 385516561596016 的匹配项中,而是将其放入匹配项 [0] 中。
我做错了什么?
【问题讨论】:
标签: node.js mongodb mongodb-query