Mongodb 更新Meteor中现有的Mongo收集对象
我看到了其他答案,比如,但是我认为我的答案更具体一点 我有Mongodb 更新Meteor中现有的Mongo收集对象,mongodb,meteor,Mongodb,Meteor,我看到了其他答案,比如,但是我认为我的答案更具体一点 我有Meteor.user()作为对象{u id:“iymu2h9uysCiKFHvc”,电子邮件:数组[2],配置文件:对象,服务:对象} 我正在运行一个函数来设置配置文件的名字和姓氏: thisId = Meteor.userId(); Meteor.users.update({ _id: thisId }, { $set: { profile: { first_name: $('#firstName').val(),
Meteor.user()
作为对象{u id:“iymu2h9uysCiKFHvc”,电子邮件:数组[2],配置文件:对象,服务:对象}
我正在运行一个函数来设置配置文件的名字和姓氏:
thisId = Meteor.userId();
Meteor.users.update({ _id: thisId }, { $set: {
profile: {
first_name: $('#firstName').val(),
last_name: $('#lastName').val()
}
}
});
但是,我还希望在另一个事件中,在概要文件中添加一个通知
对象。
我试过:
thisId = Meteor.userId();
Meteor.users.update({ _id: thisId }, { $set: {
profile: {
notifications: {
rcptDwnldFile: Session.get('recpt-dwnld-file'),
rcptPaysInv: Session.get('recpt-pays-inv'),
invSentDue: Session.get('inv-sent-due'),
// the rest
}
}
}
});
但这会覆盖我的姓
,姓
条目。我还尝试了$setOnInstert
,但更新失败:访问被拒绝。运算符$setOnInsert不允许在受限集合中使用。但我认为配置文件
在默认情况下是可由用户写入的 改用此选项(更多信息-请参阅设置嵌入文档中的字段一节):
及
thisId = Meteor.userId();
Meteor.users.update({ _id: thisId }, { $set: {
'profile.first_name': $('#firstName').val(),
'profile.last_name': $('#lastName').val()
}
});
thisId = Meteor.userId();
Meteor.users.update({ _id: thisId }, { $set: {
'profile.notifications.rcptDwnldFile': Session.get('recpt-dwnld-file'),
'profile.notifications.rcptPaysInv': Session.get('recpt-pays-inv'),
'profile.notifications.invSentDue': Session.get('inv-sent-due'),
// the rest
}
});