Adding new field on Meteor.user()

Hey Dear developers,

I am trying to add new fields on my meteor.users() collection. I know some users have asked this questions but, there is no any solution that clearly for me. I am not very good developer, and MeteorJS documentations, written for developers. I can’t understand which code belongs where? Ia it a method, belongs to server or client? How can I use this? Please can you explain step by step how can I add new field like name or surname on Meteor.user()?

1 Like

Assuming you have no schema you can just add them like you would any other JSON object.

Meteor.users.update({_id:<some_id>}, {$set: {"profile.name":"Kris"}});

Here’s a little catch that got me starting out.

Say you have a field you want in your Meteor.user() call on your client that isn’t there by default. you have to add a Meteor.publish with the first parameter being null, and change it to find the current user and include that field.

Meteor.publish(null, function () {
  return Meteor.users.find({
    _id: this.userId
  }, {
    fields: {
      mySpecialField: 1
    }
  });
});
3 Likes

We now have a section on this in the Meteor Guide:

1 Like