Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-24727

Find command returns incorrect number of documents when singleBatch is true and limit is greater than 101

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Query 17 (07/15/16)

      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.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: