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.

  • The current description isn't entirely clear. Can you confirm: s0 is a member of a replica set rs0 and you want to copy an unsharded collection from this replica set into a sharded collection in another deployment with minimal downtime? Also, what version of MongoDB are you using? – Stennie Jul 13 '17 at 9:53
  • I think have mixed terms node, replica set, cluster, shard... From single node, you can start building replica set, that requires boot (restart) of node once. Cluster infrastructure (config servers, mongoS) can be build "background", without interference to replica set or clients. Replica set can be connected to cluster (as shard) without downtime, but client must be restart, so it connects to mongoS and not directly to replica set. Additional replica sets (shards) can be then added to cluster without any down time. As can collection be sharded without downtime. – JJussi Jul 13 '17 at 11:48
  • @Stennie Yes. That is what I meant. MongoDB version - 3.4.6 – ankshah Jul 14 '17 at 8:47

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.

  • I want to set up the replica just to shard the collection without impact on existing server. What you have mentioned would be basically same as sharding the existing collection on existing setup. – ankshah Jul 14 '17 at 8:50
  • "Sharding the collection" means that you are partitioning collections data to multiple servers. Of course you can always build cluster (bunch of shards) and replicate data from already existing node/replica with mongo-connector github.com/mongodb-labs/mongo-connector – JJussi Jul 14 '17 at 9:47
  • The answer makes sense after the edit. Will check out mongo connector. – ankshah Jul 14 '17 at 20:04
  • ..and when mongo-connector approach works.. Don't for get to vote my answer. :) Even I understood what you meant first wrongly. – JJussi Jul 15 '17 at 7: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.