My Mongo DB is sharded… now what?

Now that your mongodb cluster and shards of servers/replicasets are setup, in an architecture such as then it is time to define the sharding mechanism.
1. You can define sharding at the DB level using:
2.Then all you need to do is define sharding at the Collection level using:
sh.shardCollection(“<database_name>.<collection_name>, shard-key-pattern)
Example.1 : Regular Shard
sh.shardCollection(“stats_db.counters”, { “metric_name” : 1, “metric_val” : 1 }
Example.2 : Hashed Index

Sharding [Optional (from Mongo 2.4 onwards)] –

db.counters.ensureIndex( { "_id" : "hashed" } )
sh.shardCollection(“stats_db.counters”, { “metric_val” : 1, “_id” : 1 }
These commands serve more as a reference, you should have thoroughly read through before attempting any of the above commands.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s