I need to add an additional field inside Users collection of meteor. So what I am doing is in the below server.js file I am adding following code.
//server.js
Meteor.publish("users", function () {
if (this.userId) {
return Meteor.users.find({_id: this.userId},
{fields: {'notified': 1}});
} else {
this.ready();
}
});
The client.js is as follows:
// client.js
Deps.autorun(function() {
Meteor.subscribe('users');
});
The fixture.js is as follows in order to add the field while a new user logged-in:
// fixture.js
Accounts.onCreateUser(function (options, user) {
if (options.profile) {
user.profile = options.profile;
user.profile.notified = false;
}
return user;
});
In the code I am updating the notified field like this
// inside a loop taking all the users of the collection
// where myUsers is the loop index.
Meteor.users.update(myUsers._id, {$addToSet: {notified : 1}});
But to my surprise when I am checking whether the field has been added in the collection either via mongo console or browser console, it is not showing up. Why so?. I have read almost all the articles available on net and followed http://docs.meteor.com/#meteor_users, still not working. So, anyone knows what should be done? I am clueless.