我需要将字段content设置为id给出的point元素。
{
"_id" : "kuwBhxAwEsJxc6oXc",
"points" : [
{
"id" : "xdB8TbFweTbc9fecg",
"pos" : [
604,
169
]
},
{
"id" : "uLoorpzQWm49KZ4w3",
"pos" : [
197,
176
]
}
}
}所以我得到了docId = kuwBhxAwEsJxc6oXc,pointId = uLoorpzQWm49KZ4w3和content = 'anything'。我试过这个:
Collection.update(
{ _id: docId, 'points.id': pointId },
{ $set: { content: content } }
);其结果应该是:
{
"_id" : "kuwBhxAwEsJxc6oXc",
"points" : [
{
"id" : "xdB8TbFweTbc9fecg",
"pos" : [
604,
169
]
},
{
"id" : "uLoorpzQWm49KZ4w3",
"pos" : [
197,
176
],
"content": "anything"
}
}
}发布于 2015-11-25 22:11:14
需要在更新中使用$运算符,如下所示:
Collection.update(
{_id: docId, 'points.id': pointId},
{$set: {'points.$.content': content}}
);https://stackoverflow.com/questions/33926890
复制相似问题