- Reference >
mongoShell Methods >- Database Methods >
- db.copyDatabase()
db.copyDatabase()¶
On this page
Definition¶
-
db.copyDatabase(origin, destination, hostname)¶ Copies a single logical database from a remote MongoDB instance to the local database.
db.copyDatabase()wraps thecopydbdatabase command, and takes the following arguments:Parameter Type Description originstring The name of the database on the origin system. destinationstring The name of the database to copy the origin database into. hostnamestring 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 thehostnameargument, MongoDB assumes the origin and destination databases are on the local instance.The
clonedatabase command provides related functionality.
Example¶
To copy a database named records into a database named
archive_records, use the following invocation of
db.copyDatabase():