Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 更新Meteor中现有的Mongo收集对象_Mongodb_Meteor - Fatal编程技术网

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          
  }
});