Hello,
I ran into the following bug on mongo 1.8.3 (64 bits): $maxScan
behaves incorrectly when limit is missing and when using an index.
It seems that when limit is missing, the maxScan parameter is ignored
if it's > 100. When setting $maxScan to 200 and iterating through a
cursor, the entire result set will be scanned through & returned,
instead of only 200 (because an index is used).
To replicate the bug use this script:
http://pastie.org/2600588
and run some queries:
> Q = {'nr': 43, 'ts': {'$lte': 100000, '$gte': 0}}
{ "nr" : 43, "ts" : { "$lte" : 100000, "$gte" : 0 } }
( there is an index on nr & ts )
> count = 0; col.find(Q)._addSpecial( "$maxScan" , 101 ).forEach( function(i) { count += 1; } ); print(count);
1063
> count = 0; col.find(Q)._addSpecial( "$maxScan" , 100 ).forEach( function(i) { count += 1; } ); print(count);
100
> count = 0; col.find(Q)._addSpecial( "$maxScan" , 13 ).forEach( function(i) { count += 1; } ); print(count);
13
Is this a bug, or did I misunderstand the purpose of $maxScan?
Thanks,
Mihnea @ uberVU