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

getShardDistribution() does not report "Collection XYZ is not sharded" on dropped but previously sharded collections

    • Fully Compatible
    • ALL
    • v4.4, v4.2, v4.0
    • Sharding 2019-10-21, Sharding 2019-11-04, Sharding 2019-11-18, Sharding 2020-04-20
    • 0

      Once a sharded collection has been successfully dropped, operations on it should be identical to if it had never existed, and to if it was to be implicitly re-created as a new unsharded collection. However, after a sharded collection has been dropped, db.coll.getShardDistribution() reports the error "Unable to retrieve storageStats in $collStats stage: Collection [test.test] not found." instead of the expected message "Collection test.test is not sharded." (which is the message obtained if the collection had never previously existed, or had previously existed but unsharded).

      Original summary: getShardDistribution() erroneously reports "Collection XYZ is not sharded"
      Original description:
      If collStats exceeds the maxBSONSize of 16MB due to a lot of shard metadata, getShardDistribution() erroneously reports that the collection is not sharded. This is caused by the function not checking for an error in the collStats command:

      > db.COLL.getShardDistribution
      function () {
          var stats = this.stats();
          if (!stats.sharded) {
              print("Collection " + this + " is not sharded.");
          ... logic to print shard stats ...

      The stats.sharded property doesn't exist if stats contains an error message, which is why getShardDistribution() reports a collection as unsharded if its shard metadata causes the collStats command to fail.

            kevin.pulo@mongodb.com Kevin Pulo
            james.kovacs@mongodb.com James Kovacs
            0 Vote for this issue
            7 Start watching this issue