Search code examples
mongodb

How to check whether the collection is sharded or not in Mongodb


I Wrote

db.runCommand({enablesharding : "database"})

db.runCommand({shardcollection : "database.coll_1",key : {_id :"hashed"}})

And how to check is collection sahrded or not? Maybe exist some function that I do not know. Plese help me!


Solution

  • connect to mongos and run the following:

    use config;
    db.collections.find( {_id: "db.colname" , dropped : false } )
    

    if collection is shared it'll appear there along with it sharding key