mongoid / origin

A Ruby DSL for building MongoDB queries
http://mongoid.org/en/origin/index.html
MIT License
62 stars 29 forks source link

about limit option #74

Closed simlegate closed 11 years ago

simlegate commented 11 years ago
class Band
    include Mongoid::Document
    field :name
end

Band.create(name: 'simle')
Band.create(name: 'gate')

Band.limit(1).length   #=> 2 

why not 1 ?

arthurnn commented 11 years ago

You can see that length calls .count method without passing any argument, https://github.com/mongoid/mongoid/blob/3.1.0-stable/lib/mongoid/contextual/mongo.rb#L291, this means that limit wont be used on your count query, when you wanna use limit in your count you must call .count(true).