mongoid .limit does not work in mongoid 3.1.x

前端 未结 3 1296
抹茶落季
抹茶落季 2021-02-19 18:34

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条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 19:00

    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.

提交回复
热议问题