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

sitoto · October 31, 2012 · Last by steven_yue replied at November 01, 2012 · 3679 hits

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)

You need to Sign in before reply, if you don't have an account, please Sign up first.