4

我正在使用'mongo', '1.6.2''mongoid', '2.4.11'。我有 ProPlayer 模型,当我在控制台中运行时。

irb(main):006:0> ProPlayer.first
=> #<ProPlayer _id: 508a5549d3966f02e7000001, _type: nil, created_at: nil, updated_at: nil, first_name: "Adam", last_name: "Jones", batting_style: "R", image_thumbnail: "1.jpg", is_pro_player: true, team_id: BSON::ObjectId('508a550ad3966f02ce000012'), token_id: nil>

此处使用 is_pro_player 记录为真实存在,但是当我运行 where 查询时,返回零记录,但实际上存在 71 条记录。

irb(main):008:0> ProPlayer.where(:is_pro_player=>true).to_a.size
=> 0

这个查询以前可以工作,但突然不工作了。谁能告诉我可能是什么问题?

4

2 回答 2

0

我遇到了同样的问题,我通过将类型从“Boolean”更改为“Mongoid::Boolean”来解决它,然后它将开始将布尔值作为“true”和“false”而不是“1”和“0”放入数据库中" 和 "where" 条件将再次开始工作

于 2014-01-15T11:33:06.680 回答
0

尝试以下操作:

ProPlayer.where(:is_pro_player.exists => true, is_pro_player: true).count
于 2013-07-23T07:22:07.727 回答