【发布时间】:2016-11-10 13:18:33
【问题描述】:
我有一个项目集合 (Projects),记录 project 有一个数组 equipInfo,假设我想更新数组中索引 1 的数量:
"techInfo" : {
"equipInfo" : [
{
"item" : {
"$ref" : "equipment",
"$id" : ObjectId("581a20cb4abab607fd17f07d")
},
"quantity" : "22800",
"type" : "module"
},
{
"item" : {
"$ref" : "equipment",
"$id" : ObjectId("581a20cb4abab607fd17f07e")
},
"quantity" : "1666", <===== UPDATE THIS!!!!!!
"type" : "inverter"
}
]
}
所以我尝试了:
Projects.update(
{_id: projectId},
{$set: {"techInfo.equipInfo.1.quantity": 1000000}
);
但这不起作用,我正在使用 Meteor.js 顺便说一句
【问题讨论】:
-
使用 0 {$set: {"techInfo.equipInfo.1.quantity": 1000000} 检查我的答案
-
你是在客户端还是在服务器上试了?你收到错误了吗?与您预期的结果不同?正如其他人所提到的,您的语句甚至无法编译(语法错误)。
-
这是一个虚假的问题吗?看起来接受的答案中的代码与您的原始问题匹配。
标签: mongodb meteor mongodb-query angular-meteor