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

mongos 3.2.10, sharded cluster, skip returns duplicates

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • ALL
    • Query 2017-02-13

      Hi,
      I have a sharded cluster - 2 replicasets - using MongoDB 3.2.10. The database contains a sharded collection called dataSources. When I retrieve all dataSources in batches (pages) of 500 at a time using the skip() and limit() operators, mongoS returns duplicates.

      This can be verified using the following script:

      var dsIds = {};
      var skip = 0;
      var limit = 500;
      for (;;) {
        var count = 0;
      
        print("reading page, skip=" + skip);
      
        db.dataSources.find().skip(skip).limit(limit).forEach(function(ds) {
          dsId = ds._id;
          var oldVal = dsIds[dsId];
          if (oldVal != null) {
            print("duplicate: " + dsId);
          }
          dsIds[dsId] = 1;
          count = count + 1;
        })
        print("read " + count + " docs");
      
        skip = skip + count;
        if (count < limit) {
          print("all done");
          break;
        }
      }
      

      The script prints several lines with "duplicate: ....".

      When run against the same database but MongoDB 3.0.4 mongoD + mongoS, the script detects no duplicates.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            alessandro.gherardi@yahoo.com Alessandro Gherardi
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: