Reputation: 197
I'm currently building a mini app that takes in a user login into Facebook for an event. There is no determining how many people will login, hence, mongoDB will be updated as users (clients) log in. However, I'm trying to insert an additional boolean field in Meteor's users collection and I'm not sure how to go about doing that. Here is my accounts.js code (server-side) that add's in users
Accounts.onCreateUser(function (options, user) {
if (options.profile) {
//want the users facebook pic and it is not provided by the facebook.service
options.profile.picture = "http://graph.facebook.com/" + user.services.facebook.id + "/picture/?type=large";
data = user.services.facebook;
user.profile = options.profile;
user.profile.voted = false;
}
return user;
});
Currently, I'm assigning the boolean field ("voted") to the profile field. But I can't seem to update this boolean value from the client-side js. The code I've got over here is shown below
Template.skills.events({
'click input.inc': function () {
Skills.update(Session.get("selected_skill"), {$inc: {mana: 1}});
//Meteor.users.update({_id:Meteor.default_connection.userId()},{$set:{profile.name:true}});
alert(Meteor.user().profile.name);
}
});
FYI:skills.events is merely a handlebar (Handlebars.js) that is triggered when a button is clicked. The attempt here is to update MongoDB when the button is clicked.
I'm pretty new to Meteor and hope the information provided is sufficient.
Upvotes: 2
Views: 1847
Reputation: 19544
You just add one.
user.voted = false;
If you want to access the field on the client side, make sure to create additional subscription channel for it. Meteor does not publish custom user properties by default.
Upvotes: 2