Another common task with databases is copying them. Copying a database creates a duplicate of the database that is exactly the same except for the name. There are several reasons you might want to copy a database—for example, to have a backup while you perform heavy changes or as an archive.
To create a copy of a database, you switch to that database and then use copyDatabase(origin, destination, [hostname
]) to create a copy. The origin
parameter is a string that specifies the name of the database to copy. The destination
parameter specifies the name of the database to create on this MongoDB server. The optional hostname
parameter specifies a hostname of the origin database MongoDB server if you are copying a database from a different host. For example:
db.copyDatabase('customers', 'customers_archive')