Jon Potts
Jon Potts

Reputation: 63

Using Meteor.users.update to update selected users data

I have code that stores and shows me the userID for a selected user on my leaderboard.

'click .player': function(){
  var playerId = this._id;
  Session.set('selectedPlayer', playerId);
}

Using the code below (in the client) if they click a button called increment it should add 5 "threat" to the selected users threat... however it doesn't. I see it try and tick over but it goes back to the original number. (i'm assuming cause it's not on the server)

'click input.increment': function(){
  var selectedPlayer = Session.get('selectedPlayer');
  Meteor.users.update({_id: selectedPlayer}, {$inc: {'threat': 5}});
}

So I tried to change the click to this.

'click input.increment': function(){
  var selectedPlayer = Session.get('selectedPlayer');
  Meteor.call('incclick','selectedPlayer');
}

And put the code below in a method on the server using a meteor.call. Still the threat does not update.

incclick: function (selectedPlayer) {
  Meteor.users.update({_id: selectedPlayer}, {$inc: {'threat': 5}});
},

I am thinking it is either something about how I am using selectedPlayer in the _id: area. However I have tried a lot of things and looked around... not really sure what it is.

Upvotes: 0

Views: 44

Answers (1)

kaoskeya
kaoskeya

Reputation: 1091

In your Meteor.call('incclick','selectedPlayer'); you are passing 'selectedPlayer' as a string, not the variable.

Change it to Meteor.call('incclick', selectedPlayer);

Upvotes: 1

Related Questions