我在Meteor用户个人资料中有以下内容:
{
"_id": "dwdtWPFjugF3sTLmE",
"emails": [
{
"address": "armin@four1five.com",
"verified": false
}
],
"profile": {
"name": "Armin",
"tasks": [
{
"task": "Task one",
"completed": false,
"created": "2017-10-16T18:48:21.331Z"
},
{
"task": "Task Two",
"completed": false,
"created": "2017-10-16T18:48:25.898Z"
}
]
},
"username": "armin"
}
如何通过“创建”查询,并更新“已完成”字段?或者我的做法有什么问题:
Meteor.users.update(
{ _id: Meteor.userId(), "profile.tasks.created": created },
{
$set: {
'profile.tasks.completed': completed
}
}
);
答案 0 :(得分:2)
您
$set: {
'profile.tasks.completed': completed
}
应该像positional operator '$'那样使用:
$set: {
'profile.tasks.$.completed': completed
}