How to partly update meteor.users.profile?

后端 未结 2 823
攒了一身酷
攒了一身酷 2020-12-30 05:28

I have started a min app based on meteor boilerplate with the module accounts-ui.

There is a collection created call users one of its elements is profile, this again

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 05:45

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

提交回复
热议问题