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

dataSize command requires shard key, which fails on collections where shard key is prefix of a compound multikey index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • ALL
    • Sharding 17 (07/15/16)

      We have a collection that is sharded on the key "s". There is a compound index on

      { s : 1, s2 :1 }

      , but no index on just

      { s : 1 }

      . Everything works fine related to sharding.

      However, when running the dataSize command against a mongoS, there is no way to get it to work. Passing it the shard key results in:

      db.runCommand({ datasize : "database.collection", keyPattern : { "s" : 1 }, min : { "s" : -999999 }, max : { "s" : 0 }})
      {
      	"estimate" : false,
      	"ok" : 0,
      	"errmsg" : "couldn't find valid index containing key pattern",
      	"$gleStats" : {
      		"lastOpTime" : Timestamp(0, 0),
      		"electionId" : ObjectId("000000000000000000000000")
      	}
      }
      

      Passing in the compound key results in:

      mongos> db.runCommand({ datasize : "database.collection", keyPattern : { "s" : 1, "s2" : 1 }, min : { "s" : -9999999, "s2" : -9999999 }, max : { "s" : 0, "s2" : 0 }})
      {
      	"code" : 13408,
      	"ok" : 0,
      	"errmsg" : "exception: keyPattern must equal shard key"
      }
      

      It seems that either mongo shouldn't allow you to shard a collection based on only the prefix of a compound index, or the dataSize command should be smart enough to use the compound index in this situation. I think the latter is preferable.

            Assignee:
            schwerin@mongodb.com Andy Schwerin
            Reporter:
            dai@foursquare.com Dai Shi
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: