How to partly update meteor.users.profile?

笑着哭i 提交于 2019-11-30 06:47:39

You're replacing the entire existing profile object with your data object, so anything that was there before, including the name key, is going to be wiped out.

If name is the only thing in profile that you want to keep, just add it to your data object with its own key. That way the new object you place under profile will have a name field that is equivalent to the old one.

var data = SimpleForm.processForm(event.target);
data.name = Meteor.user().profile.name;
Meteor.users.update(Meteor.userId(), {$set: {profile: data}});

You can easily keep the old profile data while updating the parts you want changed like this:

Meteor.users.update(id, {$set: {"profile.someNewField": newData}});

Make sure "profile.someNewField" is in quotes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!