How to view sharding keys in mongodb shell?

Morgan Cheng picture Morgan Cheng · Apr 2, 2012 · Viewed 13k times · Source

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?

Answer

Brendan W. McAdams picture Brendan W. McAdams · Apr 2, 2012

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.