Search code examples
mongodbsharding

How to view sharding keys in mongodb shell?


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?


Solution

  • 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.