我有一个示例用户,我想要Meteor.users.update
:
{
"_id": "BfoZ6uWcaPbNwTLGT",
"nodeHistory": [
{
"_nodeHistoryMomentId": "6dcdc770e820aa985fe3a19b",
"date": "2015-07-28T19:46:30.002Z",
"numNodes": 4,
"endDate": null,
"priceForClusterTime": null
}
],
"emails": [
{
"address": "bfs@gmg.com",
"verified": false
}
],
"profile": {
"name": "alexCl"
}
}
具体来说,我正在尝试更新给定用户对象中的 endDate
和 priceForClusterTime
字段。我试图更新 nodeHistory
列表中的特定元素(通过 _nodeHistoryMomentId
),但它没有找到我正在查找的元素(因此没有更新)。如何修改我的 mongo 参数来执行此更新?
非常感谢!
服务器代码:
totalPrice = 200.00
rightNow = new Date()
Meteor.users.update(
{ _id: Uid, "nodeHistory": {"_nodeHistoryMomentId": previousNodeSetup._nodeHistoryMomentId} },
{
$set: {
endDate: rightNow,
priceForClusterTime: totalPrice
}
},
function(error) {console.log('did not find, and/or did not insert')}
);
最佳答案
只需使用节点的完整路径在 $set:
中指定它,并确保将路径放在引号中。
{
$set: {
"nodeHistory.endDate": rightNow,
"nodeHistory.priceForClusterTime": totalPrice
}
关于javascript - Meteor.users.update 用户对象内列表中的元素 [Meteor],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31686243/