How to Move a MongoDB Collection Between Databases

If you need to move a collection between two MongoDB databases, there is no need to dump and restore your data using mongodump / mongorestore.

In a way, it's pretty similar to what we can do with  MySQL's "RENAME TABLE" command:
In the background, MongoDB will dump and restore it automatically. There is no metadata "magic" for such a rename since databases reside in different files on disk. It just saves a bit of work, and it's worth knowing about.


  1. Great thanks!
    should switch to use admin database before running this command, as described in:

  2. what if sourcedb is on server (with or without some credentials) and targetdb is on How would the command look like?

  3. you'll want to use db.cloneCollection() to copy from someDatabase on to someDatabase on, and then if you need the collection in aDifferentDatabase on, use the renameCollection command as described above to move it over.

  4. If we use this, and there is existing data in the new database, will it overwrite it or add to it?
    For example, myDatabase (original) copy registrations collection to historyDatabase.registrations. If there is already data in historyDatabase.registrations will it be overwritten or appended?