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

count() on a sharded cluster includes orphan documents

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.6
    • Component/s: Sharding
    • None
    • Environment:
      Ubuntu 12.04
    • ALL

      mongos> sh.status()
      --- Sharding Status --- 
        sharding version: {
      	"_id" : 1,
      	"version" : 3,
      	"minCompatibleVersion" : 3,
      	"currentVersion" : 4,
      	"clusterId" : ObjectId("52aaf42ca34a2646b68b9333")
      }
        shards:
      	{  "_id" : "shard0000",  "host" : "localhost:27001" }
      	{  "_id" : "shard0001",  "host" : "localhost:27002" }
      	{  "_id" : "shard0002",  "host" : "localhost:27003" }
        databases:
      	{  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
      	{  "_id" : "test",  "partitioned" : true,  "primary" : "shard0000" }
      		test.somecollection
      			shard key: { "_id" : 1 }
      			chunks:
      				shard0001	1
      				shard0002	1
      				shard0000	1
      			{ "_id" : { "$minKey" : 1 } } -->> { "_id" : 3 } on : shard0001 Timestamp(2, 0) 
      			{ "_id" : 3 } -->> { "_id" : 6 } on : shard0002 Timestamp(3, 0) 
      			{ "_id" : 6 } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(3, 1) 
      
      mongos> db.somecollection.find()
      { "_id" : 1, "data" : "one" }
      { "_id" : 3, "data" : "three" }
      { "_id" : 6, "data" : "six" }
      { "_id" : 2, "data" : "two" }
      { "_id" : 4, "data" : "four" }
      { "_id" : 7, "data" : "seven" }
      { "_id" : 5, "data" : "five" }
      { "_id" : 8, "data" : "eight" }
      { "_id" : 9, "data" : "nine" }
      { "_id" : 10, "data" : "ten" }
      mongos> db.somecollection.find().count()
      10
      
      // Connect directly to a shard and insert a document that shouldn't be on that shard (an orphan document)
      $ mongo --port 27001
      MongoDB shell version: 2.4.8
      connecting to: 127.0.0.1:27001/test
      > db.somecollection.find()
      { "_id" : 6, "data" : "six" }
      { "_id" : 7, "data" : "seven" }
      { "_id" : 8, "data" : "eight" }
      { "_id" : 9, "data" : "nine" }
      { "_id" : 10, "data" : "ten" }
      > db.somecollection.insert( { _id : 1, data : "one (orphan document)" } )
      > db.somecollection.find()
      { "_id" : 6, "data" : "six" }
      { "_id" : 7, "data" : "seven" }
      { "_id" : 8, "data" : "eight" }
      { "_id" : 9, "data" : "nine" }
      { "_id" : 10, "data" : "ten" }
      { "_id" : 1, "data" : "one (orphan document)" }
      
      // Back on mongos, the orphan document is not visible. This is correct.
      mongos> db.somecollection.find()
      { "_id" : 1, "data" : "one" }
      { "_id" : 3, "data" : "three" }
      { "_id" : 6, "data" : "six" }
      { "_id" : 2, "data" : "two" }
      { "_id" : 4, "data" : "four" }
      { "_id" : 7, "data" : "seven" }
      { "_id" : 5, "data" : "five" }
      { "_id" : 8, "data" : "eight" }
      { "_id" : 9, "data" : "nine" }
      { "_id" : 10, "data" : "ten" }
      
      // But count() includes it. This is wrong.
      mongos> db.somecollection.find().count()
      11
      
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            henrik.ingo@mongodb.com Henrik Ingo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: