Reputation: 4177
I've got a method which updates a user field. This works but just on client, if I reload the app this field starts from 0 again.
Method:
Meteor.methods({
addPublication: function (publications) {
check(publications, Number);
Meteor.users.update(this.userId, {
$set:{
publications: publications
}
});
}
});
Controller:
Meteor.call('addPublication', Meteor.user().publications + 1);
Allow new values:
Meteor.users.allow({
update: function(userId, user) {
console.log('UPDATE USER');
return true;
}
});
Publish:
Meteor.publish('users', function() { return Meteor.users.find({}, { fields: { emails: 1, profile: 1, username: 1, publications: 1, } }); });
Meteor.subscribe('users');
Am I missing something here?
Upvotes: 0
Views: 134
Reputation: 65
You should publish your method also, otherwise this method does not make any change in the database
Meteor.publish('addPublication');
If you do allow update
Meteor.users.allow({
update: function(userId, user) {
console.log('UPDATE USER');
return true;
}
});
There is no need from this method. You can just go on client:
Meteor.users.update(Meteor.userId(), {
$set:{
publications: publications
}
});
Upvotes: 0