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

dataSize cmd should ignore current database in mongos

    • Fully Compatible
    • Sharding 11 (03/11/16)

      When running dataSize in a mongos, the command only works when the current database matches the database of the collection whose size you're trying to measure.

      For example, if I have a collection test.users, this works:

      mongos> use test
      switched to db test
      mongos> db.runCommand({"dataSize": "test.users", "keyPattern": {"username": 1}, "min": {"username": 0}, "max": {"username": 7000}})
      { "size" : 200000, "numObjects" : 5000, "millis" : 5, "ok" : 1 }
      

      However, if the current database is not test, then the shell erroneously reports that the collection is empty:

      mongos> use admin
      switched to db admin
      mongos> db.runCommand({"dataSize": "test.users", "keyPattern": {"username": 1}, "min": {"username": 0}, "max": {"username": 7000}})
      { "size" : 0, "numObjects" : 0, "millis" : 0, "ok" : 1 }
      

      Since the full namespace is required for the command, it makes no sense to consider the currently active database.

      This problem only occurs when connected to a mongos. If I connect directly to a mongod, dataSize correctly gives me the collection size no matter what the currently active database is:

      > use admin
      switched to db admin
      > db.runCommand({"dataSize": "test.users", "keyPattern": {"username": 1}, "min": {"username": 0}, "max": {"username": 7000}})
      {
              "estimate" : false,
              "size" : 960,
              "numObjects" : 24,
              "millis" : 0,
              "ok" : 1
      }
      

            Assignee:
            dianna.hohensee@mongodb.com Dianna Hohensee (Inactive)
            Reporter:
            kyle.suarez@mongodb.com Kyle Suarez
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: