Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 391
user3577947 Avatar asked May 02 '14 16:05

user3577947


1 Answers

I Use the following :

use dbname db.colname.getShardDistribution()

Outputs the sharding distribution if it's sharded, and Collection dbname.colname is not sharded if it's not. Check this for more details.

I also use @Scott's comment aswell (use databaseName; db.collectionName.stats().sharded) but i prefer the getShardDistribution, it's cleaner.

like image 100
MrRobot Avatar answered Oct 16 '22 08:10

MrRobot