For investigation purpose I need to get the shardkey of a given MongoDB collection.
db.getSiblingDB("mydb").mycollection.getIndexes()
gives all indexes.
db.getSiblingDB("mydb").mycollection.getShardDistribution()
gives the distribution among shards.
What is the command to use in order to get the shard key?
You can use db.printShardingStatus()
. See documentation here