This might be a dummy question, but I cannot find any clue in all online doc.
For a already-built-up mongodb cluster, How can I find which sharding key(s) is used for given collecton?
As outlined in the Sharding Administration Docs, you can use db.printShardingStatus()
to see this information.
For sharded collections it will print the key pattern.
You can login to any "mongos" instance (or config server instance) on the cluster and query against the collections collection.
use config
db.collections.find()
You can also do this from any of the drivers since it's just like running a normal query. This collection stores information about all of the sharded collections in your cluster and which keys they are sharded on.
Just use the normal status command.
sh.status()
Output copied from my shell for reference
databases:
{ "_id" : "Test1", "primary" : "atlas-<hidden>", "partitioned" : true, "version" : { "uuid" : UUID("<hidden>"), "lastMod" : 1 } }
Test1.TestCollection
shard key: { "location" : 1, "userid" : 1 }
unique: false
balancing: true
chunks:
atlas-<hidden> 172
Under databases section you will see the complete detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With