0

I set up a MongoDb sharded cluster (2 shards) as described in this tutorial.

Now, I want to test that the shard 1 (RS1) and shard 2 (RS2) works well. However, all the databases, collections and documents that I create goes in RS1 but seems to never go in RS2.

Am I missing something? How to make sure that RS2 works?

I use MongoDB shell version: 2.6.9.

1

The tutorial refers on how to setup a sharded cluster but not on how to shard collections.

The next step is to enable sharding for a database and shard one or more collections in order to distribute the data.

From the mongos first use sh.enableSharding("dbname") https://docs.mongodb.org/v2.6/reference/method/sh.enableSharding/

and then sh.shardCollection("dbname.collectionname",{shardkey:1}) https://docs.mongodb.org/v2.6/reference/method/sh.shardCollection/

You need to choose what the shard key will be. A tutorial on how to choose a shard key can be found here https://docs.mongodb.org/v2.6/tutorial/choose-a-shard-key/

  • Thanks a lot. Before I start reading it, what is a shard key and what is the purpose of it? – JLavoie Oct 23 '15 at 2:58
  • Mongo implements vertical range partitioning using one or more fields. The partitioner is the shard key. Mongo will use the shard key to determine logical ranges for your collections which called chunks. Then it will move chunks between the shards in order each shard to have an equal number of chunks. – Antonios Oct 23 '15 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.