【问题标题】:Hunting bug in Meteor collection update流星收藏更新中的狩猎错误
【发布时间】:2012-04-23 10:36:01
【问题描述】:

我正在尝试 Meteor 的排行榜示例,但在尝试随机化玩家得分时遇到了错误。

我遇到的例外是Exception while simulating the effect of invoking '/players/update' undefined

相关代码如下:

'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

我觉得我在这里做了一些很愚蠢的事情。非常感谢您的指点。

【问题讨论】:

  • 这是一个非常无用的错误消息。

标签: meteor


【解决方案1】:

update() 的第一个参数需要是文档 ID 或完整的 Mongo 选择器。您正在传递完整的播放器文档。试试这个:

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

简写为:

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

【讨论】:

  • 太棒了!感谢 Mongo 的介绍 :)
猜你喜欢
  • 2013-05-23
  • 1970-01-01
  • 1970-01-01
  • 2015-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多