0
votes

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:

  • Server

Meteor.publish('users', function() { return Meteor.users.find({}, { fields: { emails: 1, profile: 1, username: 1, publications: 1, } }); });

  • Client

Meteor.subscribe('users');

Am I missing something here?

1
- No errors but 'UPDATE USER' never shows on serverDani
Maybe a stupid question, but is your method defined on server?ghybs
Is not inside of isServer but is in my API folder with the rest of methods and collection. Anyway, I tried to put it inside isServer and has the same resultDani
I've got a similar method for another collection and works perfectly. It looks like the problem is only with user collectionDani
Another stupid one: how do you publish your users collection?ghybs

1 Answers

0
votes

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
        }
    });