Search code examples
meteorangular2-meteor

Update user email address in meteor


I want to update email address in meteor by :

Meteor.users.update(this._id, {$set: {"emails[0].address": "deleted_" + preEmail }});

but instead of updating email array, 0 argument, then address ,it create a new field like emails[0] then address. it is interesting that in one other .js file it works correctly!


Solution

  • You were almost there. In you code change "emails[0].address" with emails.0.address . My code is working in Angular 2 meteor. I hope it will work for you also :)

     Meteor.users.update({
            _id: id
         }, 
         {
            $set: {
                'emails.0.address': address,
                "username": username
            }
        });