I have a simple class:
class Article include Mongoid::Document end
Let's create at least 102 records (because the default batchSize of mongodb is 101):
102.times { Article.create }
Now if I make this query with the QueryCache enabled:
Mongoid::QueryCache.cache { Article.all.any?; Article.all.map(&:id).size } => 101
It does not return the correct number of articles which should be 102.
After some investigation, the reason is that the 2 commands make the same queries... except that the map makes a getMore to get the rest of the list. The QueryCache prevents the getMore from being made.
A workaround could be to use exists? or empty? but we clearly should not have an issue with any? too.
- is related to
-
MONGOID-4756 Query cache tests do not test that QC is used
- Closed
- related to
-
MONGOID-1335 find_in_batches
- Closed