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.
Best Answer
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/