mongoid .limit does not work in mongoid 3.1.x

mongodb, mongoid, ruby-on-rails

Solution

The `limit` command works fine, but for some reason `count` ignores the limit. If you cast it to an array you'll see that the limit is working.

Array(Gallery.limit(1)).length  # this gives 1

Also, if you actually iterate through the objects you'll see that the limit is working.

Problem

i tried something like this in rails with mongoid 3.1.0 and lastest 3.1.3. .limit does not work. below it should return 1 row but it returns all (4) code: ``` @go = Gallery.limit(1) logger.info "count: #{@go.count}" ``` output: ``` count: 4 MOPED: 54.234.11.193:10055 QUERY database=mongohqtestdatabase collection=galleries selector= {"$query"=>{}, "$orderby"=>{:_id=>1}} flags=[:slave_ok] limit=-1 skip=0 batch_size=nil fields=nil (276.2010 ``` ms) which version of mongoid is good with limit() ?

Original source