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

mongos does not return matching results after encountering empty documents

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.7.5
    • Component/s: Querying, Sharding
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Start a sharded cluster with 2 shards

      mlaunch --sharded 2 --single
       
      launching: mongod on port 27018
      launching: mongod on port 27019
      launching: config server on port 27020
      launching: mongos on port 27017
      adding shards.

      Insert some data, shard the collection on _id

      (ve)tr@enter:~/Documents/tickets/CS-14146$ mongo
       
      MongoDB shell version: 2.6.3
      connecting to: test
      mongos> db.getSisterDB('config').settings.update({}, {$set: {value: 1}})
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
      mongos> for (var i = 0; i < 20000; i++) {
      ... db.coll.insert({field: i})
      ... }
      WriteResult({ "nInserted" : 1 })
      mongos> sh.enableSharding('test')
      { "ok" : 1 }
      mongos> sh.shardCollection('test.coll', {_id: 1})
      { "collectionsharded" : "test.coll", "ok" : 1 }
      mongos> sh.status()
      --- Sharding Status ---
        sharding version: {
          "_id" : 1,
          "version" : 4,
          "minCompatibleVersion" : 4,
          "currentVersion" : 5,
          "clusterId" : ObjectId("53e153e61a06f4155f0e2439")
      }
        shards:
          {  "_id" : "shard0000",  "host" : "enter.local:27018" }
          {  "_id" : "shard0001",  "host" : "enter.local:27019" }
        databases:
          {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
          {  "_id" : "test",  "partitioned" : true,  "primary" : "shard0000" }
              test.coll
                  shard key: { "_id" : 1 }
                  chunks:
                      shard0000   2
                      shard0001   1
                  { "_id" : { "$minKey" : 1 } } -->> { "_id" : ObjectId("53e154266632858cc22a2205") } on : shard0000 Timestamp(2, 1)
                  { "_id" : ObjectId("53e154266632858cc22a2205") } -->> { "_id" : ObjectId("53e154436632858cc22a530d") } on : shard0000 Timestamp(1, 3)
                  { "_id" : ObjectId("53e154436632858cc22a530d") } -->> { "_id" : { "$maxKey" : 1 } } on : shard0001 Timestamp(2, 0)

      Run a query that would return an empty document:

      mongos> db.coll.find({}, {nonexisting:1, _id:0})
      mongos> db.coll.find({}, {nonexisting:1, _id:0}).itcount()
      0
      mongos> db.coll.find({}, {nonexisting:1, _id:0}).count()
      20000
      mongos>
      bye

      On mongod however:

      (ve)tr@enter:~/Documents/tickets/CS-14146$ mongo --port 27018
      MongoDB shell version: 2.6.3
      connecting to: 127.0.0.1:27018/test
      > db.coll.find({}, {nonexisting:1, _id:0})
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      {  }
      Type "it" for more
      > db.coll.find({}, {nonexisting:1, _id:0}).count()
      12552
      > db.coll.find({}, {nonexisting:1, _id:0}).itcount()
      12552
      >

      Show
      Start a sharded cluster with 2 shards mlaunch --sharded 2 --single   launching: mongod on port 27018 launching: mongod on port 27019 launching: config server on port 27020 launching: mongos on port 27017 adding shards. Insert some data, shard the collection on _id (ve)tr@enter:~/Documents/tickets/CS-14146$ mongo   MongoDB shell version: 2.6.3 connecting to: test mongos> db.getSisterDB('config').settings.update({}, {$set: {value: 1}}) WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) mongos> for (var i = 0; i < 20000; i++) { ... db.coll.insert({field: i}) ... } WriteResult({ "nInserted" : 1 }) mongos> sh.enableSharding('test') { "ok" : 1 } mongos> sh.shardCollection('test.coll', {_id: 1}) { "collectionsharded" : "test.coll", "ok" : 1 } mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "version" : 4, "minCompatibleVersion" : 4, "currentVersion" : 5, "clusterId" : ObjectId("53e153e61a06f4155f0e2439") } shards: { "_id" : "shard0000", "host" : "enter.local:27018" } { "_id" : "shard0001", "host" : "enter.local:27019" } databases: { "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "test", "partitioned" : true, "primary" : "shard0000" } test.coll shard key: { "_id" : 1 } chunks: shard0000 2 shard0001 1 { "_id" : { "$minKey" : 1 } } -->> { "_id" : ObjectId("53e154266632858cc22a2205") } on : shard0000 Timestamp(2, 1) { "_id" : ObjectId("53e154266632858cc22a2205") } -->> { "_id" : ObjectId("53e154436632858cc22a530d") } on : shard0000 Timestamp(1, 3) { "_id" : ObjectId("53e154436632858cc22a530d") } -->> { "_id" : { "$maxKey" : 1 } } on : shard0001 Timestamp(2, 0) Run a query that would return an empty document: mongos> db.coll.find({}, {nonexisting:1, _id:0}) mongos> db.coll.find({}, {nonexisting:1, _id:0}).itcount() 0 mongos> db.coll.find({}, {nonexisting:1, _id:0}).count() 20000 mongos> bye On mongod however: (ve)tr@enter:~/Documents/tickets/CS-14146$ mongo --port 27018 MongoDB shell version: 2.6.3 connecting to: 127.0.0.1:27018/test > db.coll.find({}, {nonexisting:1, _id:0}) { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } { } Type "it" for more > db.coll.find({}, {nonexisting:1, _id:0}).count() 12552 > db.coll.find({}, {nonexisting:1, _id:0}).itcount() 12552 >

      Description

      mongos and mongod show inconsistent behavior for returning empty documents.

      In a sharded collection a find with a projection that results in an empty document is not returned by mongos but just skipped.

      mongod on the other hand returns the empty document { }.

      See steps to reproduce.

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: