使用MongoDB和Ruby驱动程序,我试图在我的应用程序中计算玩家的排名,因此我按(在本例中)俯卧撑排序,然后添加一个排名字段和每个对象的值。pushups=coll.find.sort(["pushups",-1])pushups.each_with_indexdo|r,idx|r[:pushups_rank]=idx+1coll.update({:id=>r},r,:upsert=>true)coll.save(r)end这种方法确实有效,但这是遍历对象并更新每个对象的最佳方法吗?有没有更好的方法来计算玩家的段位? 最佳答案