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

collStats should return ok:1 and all fields when the namespace does not exist

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.1.1
    • Affects Version/s: None
    • Component/s: Storage
    • Minor Change
    • Storage NYC 2018-07-02

      The "collStats" command on non-existent namespace should be consistent with other commands on non-existent namespaces, and return success (ok:1) and similar to dbStats command should return a document similar in format to that for existing collection but with 0's for sizes.

      This will also make the $collStats aggregation stage behave consistently whether only latencyStats or storageStats are requested: currently latencyStats returns a document on non-existent namespace, but storageStats generates an error. There are no other aggregation stages that generate an error on a non-existent collection that I could find.

      Original description:
      collStats does not return an error code when the database or collection does not exist:

      > db.runCommand({collStats: "not-present"})
      {
      	"ns" : "test.not-present",
      	"ok" : 0,
      	"errmsg" : "Collection [test.not-present] not found.",
      	"operationTime" : Timestamp(1497566635, 1)
      }
      > db.getSiblingDB("not-present").runCommand({collStats: "not-present"})
      {
      	"ns" : "not-present.not-present",
      	"ok" : 0,
      	"errmsg" : "Database [not-present] not found.",
      	"operationTime" : Timestamp(1497566645, 1)
      }
      

      It should also return an error code, NamespaceNotFound would be a good choice:

      > db.runCommand({collStats: "not-present"})
      {
      	"ns" : "test.not-present",
      	"ok" : 0,
      	"errmsg" : "Collection [test.not-present] not found.",
      	"code" : 26,
      	"codeName" : "NamespaceNotFound",
      	"operationTime" : Timestamp(1497566635, 1)
      }
      > db.getSiblingDB("not-present").runCommand({collStats: "not-present"})
      {
      	"ns" : "not-present.not-present",
      	"ok" : 0,
      	"errmsg" : "Database [not-present] not found.",
      	"code" : 26,
      	"codeName" : "NamespaceNotFound",
      	"operationTime" : Timestamp(1497566645, 1)
      }
      

            Assignee:
            ben.judd Ben Judd
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: