How to partly update meteor.users.profile?

后端 未结 2 808
攒了一身酷
攒了一身酷 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}});
    
    0 讨论(0)
  • 2020-12-30 05:47

    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.

    0 讨论(0)
提交回复
热议问题