Raman
Raman

Reputation: 885

MongoDB: how to copy database/collection with indexes?

I need to migrate a big amount of data from one mongo replica (src) to another (dst). But it's important to leave data on dst instance in available state. I'm going to use copyDatabase command for such needs. Do I have a chance to copy already indexes too? It could exclude effort on its recreation in dst instance? Recreation influences dramatically on secondary nodes by reason that process run in foreground and I want minimize it as much as possible.

Thanks for any help or advises.

Upvotes: 2

Views: 2785

Answers (1)

Chris
Chris

Reputation: 3102

copyDatabase() will not copy the indexes, and so they'll be recreated on the destination after the import.

If you're running your source mongod instance with journaling enabled (the default in v2.0+), you can simply copy the contents of the data directory (the folder containing lots of files in the format collection_name.0, collection_name.1, etc.) into the destination's data directory and then restart the destination's mongod instance.

If these instances are part of a replica set, you should only copy files relating to collections you've created, and exclude "local.x" files as these relate to the replica set's configuration.

Upvotes: 1

Related Questions