Reputation: 2378
I have created a user profile using simple schema and collection2. If the name or email address is updated I want to update the meteor user profile. When I try to set the email address in the meteor user profile it won't update. This is the offending line:
Meteor.users.update(Meteor.userId(), {$set: {emails[0].address: pDetails.contactDetails.email}});
Can anyone show me how to update the meteor user profile?
Thank you.
Upvotes: 1
Views: 1359
Reputation: 20226
You need to select the array element based on the previous email address value in your selector.
Meteor.users.update({ _id: Meteor.userId(), 'emails.address': oldAddress },
{ $set: { 'emails.0.address': newAddress }});
You may have to set the verified
field to false at the same time if the new email address is not verified. Then send the email verification email.
Upvotes: 2
Reputation: 2378
This also worked:
Meteor.users.update(Meteor.userId(), {$set: {'emails.0.address': pDetails.contactDetails.email, 'profile.name': pDetails.contactDetails.firstName}});
Upvotes: 1