【发布时间】:2013-07-03 02:20:38
【问题描述】:
我有这样的 mongo 结构:
{
"_id" : ObjectId("51596b7e469b9c3816000001"),
"company" : {
"_id" : "ade2fd0ec9b8b5e9152e0155",
"title" : "LO3426546457"
},
}
{
"_id" : ObjectId("51596cef469b9c3816000008"),
"company" : {
"_id" : "ade2fd0ec9b8b5e9152e0155",
"title" : "LO3426546457"
},
}
{
"_id" : ObjectId("51596cc3469b9c3816000007"),
"company" : {
"_id" : "ade2fd0ec9b8b5e9152e0155",
"title" : "LO3426546457"
}
}
我想更改具有特定“_id”的对象的所有“标题”字段。 我喜欢这样:
Collections.UsersCollection.update({
'company._id': 'ade2fd0ec9b8b5e9152e0155'
}, {
$set: {
'company': { _id: 'ade2fd0ec9b8b5e9152e0155', title: 'blablabla' }
// I also tried: 'company.title': 'blablabla'
}
}, false, true);
在 Node.js 中执行该代码后(我使用 node-mongodb-native),mongo 只更新一个文档。
但如果我在 Mongo Shell (mongo.exe) 上执行该命令,一切正常并更新所有文档。
有什么问题?
【问题讨论】:
-
你说该命令在 mongo shell 中有效,但在哪里无效?
-
哦,对不起。它在我的 Node.js 代码中不起作用。我使用这个模块:github.com/mongodb/node-mongodb-native
标签: node.js mongodb node-mongodb-native