Navigation

db.copyDatabase()

On this page

Definition

db.copyDatabase(fromdb, todb, fromhost, username, password, mechanism)

Deprecated since version 4.0.

Important

Starting in version 4.2, MongoDB removes the copydb command. The deprecated db.copyDatabase(), which wraps the copydb command, can only be run against MongoDB 4.0 or earlier versions. For behavior and examples, refer to the 4.0 or earlier version of the manual.

For an alternative in version 4.2+, see Copy/Clone a Database.

Copies a database either from one mongod instance to the current mongod instance or within the current mongod.

The mongo shell method db.copyDatabase() takes the following arguments:

Parameter Type Description
fromdb string Name of the source database.
todb string Name of the target database.
fromhost string Optional. The hostname of the source mongod instance. Omit to copy databases within the same mongod instance.
username string

Optional. The name of the user on the fromhost MongoDB instance. The user authenticates to the fromdb.

For more information, refer to the 4.0 or earlier version of the manual.

password string

Optional. The password on the fromhost for authentication. The method does not transmit the password in plaintext.

For more information, refer to the 4.0 or earlier version of the manual.

mechanism string

Optional. The authentication mechanism on the fromhost.

The fromhost credentials must use SCRAM-SHA-1.

Changed in version 4.0: copyDatabase() no longer supports MONGODB-CR to authenticate to the fromhost.