Reputation: 2662
How can I edit the user details in users collection in my meteor app.My code is
Meteor.users.update({_id:this._id}, { $set:{"profile.name":pname}} )
This is working only for the 1st user in the list. How can I do this for all users listed ?
Upvotes: 9
Views: 6942
Reputation: 1
The problem was that you are referencing something that doesn't exists
Replace:
Meteor.users.update({_id:this._id}, { $set:{"profile.name":pname}} )
by:
Meteor.users.update({_id:this.userId}, { $set:{"profile.name":pname}} )
Or Use Meteor.userId() as @occasl suggested before.
Just happened to me
Upvotes: 0
Reputation: 5454
I found that the only way to update a Meteor user was to set the criteria using the _id with the Meteor.userId()
:
Meteor.users.update( { _id: Meteor.userId() }, { $set: { 'oauth.token': token }} );
I do this on the server side so it will block the client until success/failure from Mongo.
Upvotes: 14
Reputation: 310
As per http://docs.meteor.com/#update, set the "multi" option to "true":
Meteor.users.update({_id:this._id}, { $set:{"profile.name":pname}}, {multi: true} )
Upvotes: -2