OPTIONS

db.copyDatabase()

Definition

db.copyDatabase(origin, destination, hostname)

Copies a single logical database from a remote MongoDB instance to the local database. db.copyDatabase() wraps the copydb database command, and takes the following arguments:

Parameter Type Description
origin string The name of the database on the origin system.
destination string The name of the database to copy the origin database into.
hostname string Optional. The hostname of the origin database host. Omit the hostname to copy from one name to another on the same server.

db.copyDatabase() implicitly creates the destination databases if it does not exist. If you do not specify the hostname argument, MongoDB assumes the origin and destination databases are on the local instance.

The clone database command provides related functionality.

Example

To copy a database named records into a database named archive_records, use the following invocation of db.copyDatabase():

db.copyDatabase('records', 'archive_records')