数据库 Mongoid 的 limit 设置怎么没效?

sitoto · 2012年10月31日 · 最后由 steven_yue 回复于 2012年11月01日 · 3678 次阅读

topic = Topic.limit(100).where(:status => 0)

topic.count #30000

limit 怎么没有生效呢?

MongoID 是什么版本?我记得有的版本必须 topic.count(true) 才会 Query 的时候带上 limit 选项。

2.*.0 stable 的 count方法都是这样的 https://github.com/mongoid/mongoid/blob/2.2.0-stable/lib/mongoid/contexts/mongo.rb#L89 3.0 版本默认就会带上 limit 选项

#2 楼 @LarryLv 我的已经是 mongoid (3.0.0.rc) 了

试试这个: Topic.all.limit(100).where(:status => 0) 或者 Topic.where(:status => 0).limit(100)

需要 登录 后方可回复, 如果你还没有账号请 注册新账号