mongoid .limit does not work in mongoid 3.1.x

前端 未结 3 1610
我在风中等你
我在风中等你 2021-02-19 18:17

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:



        
3条回答
  •  梦毁少年i
    2021-02-19 19:10

    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.

提交回复
热议问题