-
Type: Bug
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Issue discovered in 7.0.11 but also exists in main (in a slightly different form)
QueryCache doesn't handle a limit of 0 correctly.Mongodb itself ignores 0 as a limit,
>> Model.collection.find({}, { limit: 1 }).to_a.length
=> 1
>> Model.collection.find({}, { limit: 0 }).to_a.length
=> 1993
But when QueryCache is turned on, it is handled incorrectly
>> Model.collection.find({}, { limit: 1 }).to_a.length
=> 1
>> Model.collection.find({}, { limit: 0 }).to_a.length
=> 0
This appears to be due to the following code:
https://github.com/mongodb/mongoid/blob/master/lib/mongoid/query_cache.rb#L259
@cursor.to_a[0...limit]
as this will always return 0 items.
MongoDB manual says:
A limit() value of 0 (i.e. .limit(0)) is equivalent to setting no limit.
so the QueryCache should also handle it in the same way and return everything