Mongorestore shard collectiong by default or not?

Hi,

Got a question.
I took a mongodump of a database with sharded collections .
Should a mongorestore of adatabase to a new sharded cluster automatically shard their collection by default?

Prior to restore I’ve enabled sharding on the database in the new env
I then did a restore myself but it doesn’t to shard the collection.

While another colleague of mine says it does and another say it doesn’t.

Regards,

KW

Hi @Kin_Wai_Cheung
Welcome to the MongoDB Community!!

No, mongorestore will not automatically shard the collection. mongodump and mongorestore only dump and restore data and indexes, and not the infrastructure of the database or collection.

If you want to restore into a sharded collection, you would need to shard the collection manually before doing the restore. Alternatively, you can also shard the collection after the restore, but typically sharding before restoring is a better approach, since the cluster won’t need to redistribute chunks full of data across the cluster after the restore.

Note that enabling sharding on a database does not automatically shard the collections (see sh.enableSharding()) as sharding a collection is a separate step.

Thanks
Aasawari

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.