The hunt for updating the Meteor collection

I tried the Meteors Leaderboard example and am in error trying to randomize player ratings.

Exception Im hit Exception while simulating the effect of invoking '/players/update' undefined

The corresponding code is as follows:

 'click input.randomize_scores': function () { Players.find().forEach(function (player) { random_score = Math.floor(Math.random()*10)*5; Players.update(player, {$set: {score: random_score}}) }); } 

The full contents of leaderboard.js are here

It seems to me that I'm doing something pretty stupid here. Id really appreciate the pointer.

+7
source share
1 answer

The first argument to update () should be the document identifier or the full Mongo selector. You transmit the complete game document. Try the following:

 Players.update(player._id, {$set: {score: random_score}}); 

which is short for:

 Players.update({_id: player._id}, {$set: {score: random_score}}); 
+15
source

All Articles