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

Count() can be wrong in sharded collections

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying, Sharding
    • Labels:
    • Minor Change
    • ALL

      The count command does not ignore orphans like find/queries. This is true whether the query is on the primary or secondaries (which is known to be a different issue).

      For a query like this the count can come back larger if there are orphaned docs, but find will filter them out:

      // more than one shard has the document with x:10, some of which are orphans from migrations
      > coll.count({x:10})
      2
      > coll.find({x:10}).toArray()
      [{_id:10, x:10}]
      > coll.find({x:10}).explain() // some of the explain is removed for brevity
      {
      	"clusteredType" : "ParallelSort",
      	"shards" : { ... },
      	"n" : 1,
      	"nChunkSkips" : 1,
      	"numQueries" : 2,
      	"numShards" : 2,
      	"millis" : 2
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            antoineguiral Antoine Guiral
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: