- Reference >
- JavaScript Methods >
- db.copyDatabase()
db.copyDatabase()¶
-
db.
copyDatabase
(origin, destination, hostname)¶ Parameters: - origin (database) – Specifies the name of the database on the origin system.
- destination (database) – Specifies the name of the database that you wish to copy the origin database into.
- hostname (origin) – Indicate the hostname of the origin database host. Omit the hostname to copy from one name to another on the same server.
Use this function to copy a specific database, named
origin
running on the system accessible viahostname
into the local database nameddestination
. The command creates destination databases implicitly when they do not exist. If you omit the hostname, MongoDB will copy data from one database into another on the same instance.This function provides a wrapper around the MongoDB database command “
copydb
.” Theclone
database command provides related functionality.Example
Given a database named
records
that you want to copy into a database namedarchive_records
, you could use the following invocation ofdb.copyDatabase()
: