I'm nidhin
I'm nidhin

Reputation: 2662

Updating user profile details in meteor not working

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

Answers (3)

Jorge Barrachina
Jorge Barrachina

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

occasl
occasl

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

FredericoC
FredericoC

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

Related Questions