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

limit() is returning less than it should at sharded collection

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.8
    • Affects Version/s: 1.8.3, 2.0.2
    • Component/s: Sharding, Shell
    • None
    • Environment:
      CentOS 5.7 (64bit)
    • ALL

      I tried query to sharded collection with limit() method at mongo shell, and sometimes got less documents than it should.

      Test code (attached below):

      test.js
      db = connect("localhost:27017/myTest");
      
      print( "Prepareing test data" );
      db.adminCommand( {enablesharding: "myTest"});
      db.myColl.drop();
      db.adminCommand( {shardcollection: "myTest.myColl", key: {key:1}} );
      var padding = ''; for (var i=0; i<10000; i++){ padding += '*'; }
      for (var i=0; i<5000; i++){ db.myColl.save({key: 0, value: i, padding: padding}); }
      
      var conf = db.getSisterDB("config");
      print( "Number of the shards : " + conf.shards.count() );
      print( "Chunks : " );
      conf.chunks.find({ns:"myTest.myColl"}).forEach(printjson);
      print( "Test result:" );
      
      for(var lm=100; lm<2000; lm+=100){
              var i=0;db.myColl.find().limit(lm).forEach(function(x){i=i+1});
              print(lm + ":" + i + (lm == i ? "" : " <- !?"))
      }
      

      and result :

      $ mongo --nodb test.js
      MongoDB shell version: 2.0.2
      connecting to: localhost:27017/myTest
      Prepareing test data
      Number of the shards : 3
      Chunks :
              "_id" : "myTest.myColl-key_MinKey",
              "lastmod" : {
                      "t" : 1000,
                      "i" : 0
              },
              "ns" : "myTest.myColl",
              "min" : {
                      "key" : { $minKey : 1 }
              },
              "max" : {
                      "key" : { $maxKey : 1 }
              },
              "shard" : "shard1" 
      }
      Test result:
      100:100
      200:115 <- !?
      300:300
      400:400
      500:500
      600:600
      700:554 <- !?
      800:454 <- !?
      900:900
      1000:1000
      1100:1100
      1200:993 <- !?
      1300:893 <- !?
      1400:793 <- !?
      1500:1500
      1600:1600
      1700:1700
      1800:1332 <- !?
      1900:1232 <- !?
      

      I tried same test via mondod(shard) directly and it's OK.
      I tried same test in single not sharded collection and it's OK.

      I tried same test with Perl driver (MongoDB 0.45 CPAN module) and it's OK. (test code and result attached)

        1. limit_return.js
          1 kB
        2. test_groovy-result.txt
          0.6 kB
        3. test_pl-result.txt
          0.2 kB
        4. test.groovy
          1 kB
        5. test.js
          0.7 kB
        6. test.pl
          0.3 kB

            Assignee:
            greg_10gen Greg Studer
            Reporter:
            ran HAMADA Ran
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: