Mongodb – sharding + replicating an existing collection

mongodbreplicationsharding

I have an existing mongo (3.4) database that is growing quickly, so I need to shard it. I am only getting started with sharding/replication and I'm going through the documentation at the moment.

Is this a logical sequence of events for sharding and replicating an existing collection:

  1. create 3x config server replica set
  2. connect the existing mongo server with the config set
  3. enable sharding on the existing db
  4. create another mongo server and connect with the config set
  5. shard existing collection
  6. create replica servers and connect with the config set

Thanks

Best Answer

Yes, you can do it just like that. Shards in the cluster don't need to be replica sets, but it is of course recommended. And later, it is possible to convert those nodes to single node replica sets and after that add more nodes to those replica sets. However, after making node as replica set, you need to do little "under the hood" updates, so that config server (and mongos) will know that shard(s) are now replica sets and not single nodes anymore.