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

mongos does not return matching results after encountering empty documents

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.7.5
    • Affects Version/s: None
    • Component/s: Querying, Sharding
    • None
    • ALL
    • 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 >

      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.

            Assignee:
            greg_10gen Greg Studer
            Reporter:
            thomas.rueckstiess@mongodb.com Thomas Rueckstiess
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: