Hunting bug in Meteor collection update

meteor

Solution

The first argument to update() needs to be a document ID or a full Mongo selector. You're passing the complete player document. Try this:

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

which is shorthand for:

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

Problem

I’m trying out Meteor’s Leaderboard example and am running into a bug in trying to randomize the players’ scores. The exception I’m hitting is `Exception while simulating the effect of invoking '/players/update' undefined` The relevant code looks like this: ``` '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}}) }); } ``` Full leaderboard.js contents here I get the feeling I’m doing something pretty silly here. I’d really appreciate a pointer.

Original source