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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: 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
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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. test.pl
          0.3 kB
          HAMADA Ran
        2. test.js
          0.7 kB
          HAMADA Ran
        3. test.groovy
          1 kB
          HAMADA Ran
        4. test_pl-result.txt
          0.2 kB
          HAMADA Ran
        5. test_groovy-result.txt
          0.6 kB
          HAMADA Ran
        6. limit_return.js
          1 kB
          Greg Studer

            Assignee:
            Greg Studer (Inactive)
            Reporter:
            HAMADA Ran
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: