-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
ALL
-
Query 17 (07/15/16)
-
None
-
0
-
None
-
None
-
None
-
None
-
None
-
None
The find command returns an incorrect number of documents when the "singleBatch" option is set to true and the "limit" option is set to a value greater than 101. In this case, the find command returns 101 documents, whereas it should return the number of documents equal to the specified "limit" value.
This affects all versions of the server since the find command was first introduced (3.2.0). It also affects the use of legacy OP_QUERY reads against mongos (which use the find command internally).
Reproduce as follows:
var st = new ShardingTest({shards: 1}); var collName = "test.foo"; var howMany = function(coll) { return coll.find().limit(-800).itcount(); } for (var i = 0; i < 1000; ++i) { st.s0.getCollection(collName).insert({}); } var mongodOpQuery = new Mongo(st.shard0.host); mongodOpQuery.forceReadMode("legacy"); assert.eq(800, howMany(mongodOpQuery.getCollection(collName))); // Passes: expected. var mongosOpQuery = new Mongo(st.s0.host); mongosOpQuery.forceReadMode("legacy"); assert.eq(800, howMany(mongosOpQuery.getCollection(collName))); // Fails: unexpectedly returns 101. var mongodFindCommand = new Mongo(st.shard0.host); mongodFindCommand.forceReadMode("commands"); assert.eq(800, howMany(mongodFindCommand.getCollection(collName))); // Fails: unexpectedly returns 101. var mongosFindCommand = new Mongo(st.s0.host); mongosFindCommand.forceReadMode("commands"); assert.eq(800, howMany(mongosFindCommand.getCollection(collName))); // Fails: unexpectedly returns 101.
Credit goes to jeff.yemin for discovering this issue.