Add mongodb cluster to a replica set

Posted on

Question :

I have a database db on mongodb server s0 with collection coll which is not sharded. To shard this collection I set up a sharded cluster and add s0 to replica set rs0. Now I want to add the sharded cluster to this replica set rs0 so that on replication the collection gets sharded in the cluster. But mongos cannot be added to a replica set. How do I add this cluster to rs0?

Note: I am aware of the other way to shard an existing collection but there are downtime considerations in that approach.

Answer :

First you convert your standalone node to replica set and you add two other nodes, so it is real replica set (one node RS is possible, but not really RS)

Cluster must have more than one RS.. It’s not cluster if you have only one shard…

Then you start to build your cluster by deploying config server replica set and at least one mongoS.

When cluster infrastructure is ready, you connect your replica set(s) to that cluster.

Now you can enable sharding of one or multiple db/collections.

Or you can move existing data to (ready made) cluster with mongo-connector.

Leave a Reply

Your email address will not be published. Required fields are marked *