copy collections to different database? Dev->QA, QA->PROD etc

25 views
Skip to first unread message

Lee Fisher

unread,
May 11, 2016, 3:46:18 PM5/11/16
to mongodb-user
Is there a preferred method to copy collections to another database?  For example when we move from DEV to QA or QA to PRODUCTION.
PRODUCTION would be 3 member replicaset, others are single instances.

Currently we use mongodump mongorestore and exclude the few collections we do not want.

Generally it works OK, but we have noticed sometimes during/after copying to PRODUCTION the replicaset members could hit 400% CPU and may cause degraded performance.

Is this the preferred method or is there another way?

Thanks,
Lee

Kevin Adistambha

unread,
May 19, 2016, 10:24:09 PM5/19/16
to mongodb-user

Hi Lee,

Is there a preferred method to copy collections to another database? For example when we move from DEV to QA or QA to PRODUCTION.
PRODUCTION would be 3 member replicaset, others are single instances.

You can use the cloneCollection database command to copy a collection from one server to another. For example, if you want to copy a collection called examples from the server dev-server in database test:

db.runCommand({cloneCollection:"test.examples",from:"dev-server:27017"})

Please note that there are some caveats with the cloneCollection command:

  • mongos does not support the command
  • it cannot be used if the source server has auth enabled
  • in MongoDB 3.0 and above, it will return an error if the collection already exists

The cloneCollection command will also copy the indexes of the source collection.

Generally it works OK, but we have noticed sometimes during/after copying to PRODUCTION the replicaset members could hit 400% CPU and may cause degraded performance.

This may be caused by the Secondary members building indexes during the import process.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages