Migrate data from a standalone (non-sharded) instance to sharded mongodb instances using mongorestore

Hi All,
Need your help in below.
We are migrating the sharded regular collections into sharded time series collection. We will be following below approach:

  1. Transform existing sharded regular collection into non sharded temporary regular collection using aggregate on mongos.
  2. Take dump of transformed temporary non sharded regular collection using mongodump on mongos.
  3. Create an empty time series collections and enable sharding (using shardCollection)
  4. Restore this dump into sharded time series collection using mongorestore.

My question here:
As we are restoring non sharded dump into empty sharded time series collection, where shard keys are already set into empty time series collection.

Is mongorestore takes care of sharding and data will be restored to multiple instances as per shardKey and zoneKeyRange into timeseries collection?

Or I need to restore the non sharded dump into empty time series collection and shard the collections (using shardCollection) after restore completes?

Thank you in advance.

In my experience option one:

is the best way to do this, I’ve found it splits the keys quicker as it moves it while it is restoring instead of restoring to one shard, then having to migrate data as a second action. I have restored a collection with 300+ million documents to an empty sharded collection (geo tags enabled) and it correctly put all documents on the right shard.

1 Like

Thank you so much for your reply.

This seems very slow. Do you know what can help to use mogorestore to sharded timeseries collection and it takes minimum time?
Right now, it is taking 50-60 minute to restore 20m records.