Reputation: 2343
I would like to insert attributes to users. If it were another collection I would add a method to a collection. How can I accomplish this with users since it is already built in with Meteor?
Upvotes: 0
Views: 29
Reputation: 64312
You'd add a method just like you would for any other collection - just use Meteor.users
as the instance. For example:
server
Meteor.methods({
'users.cats.add: function() {
Meteor.users.update(this.userId, {$inc: {cats: 1}});
}
});
client
Meteor.call('users.cats.add');
You'll find this example particularly useful of your users happen to have cats.
Upvotes: 2
Reputation: 4880
You only need to call:
Meteor.users.update({ _id: myUserId }, { $set: {
someAttribute: 'someValue'
}});
Note that this code will only work server-side. If you want to add those attributes as soon as each new account is created then Accounts.onCreateUser
would be a good place to do that. Look here:
http://docs.meteor.com/#/full/accounts_oncreateuser
for more details.
Upvotes: 1