anon
anon

Reputation: 2343

How do I insert attributes for users/accounts with MeteorJS?

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

Answers (2)

David Weldon
David Weldon

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

Tomasz Lenarcik
Tomasz Lenarcik

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

Related Questions