db.copyDatabase()

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 copydbcommand, can only be run against MongoDB 4.0 or earlier versions.For behavior and examples, refer to the 4.0 or earlier version ofthe manual.

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

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

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

ParameterTypeDescriptionfromdbstringName of the source database.todbstringName of the target database.fromhoststringOptional. The hostname of the source mongod instance. Omitto copy databases within the same mongod instance.usernamestringOptional. The name of the user on the fromhost MongoDB instance. The userauthenticates to the fromdb.

For more information, refer to the 4.0 or earlier version of themanual.passwordstringOptional. The password on the fromhost for authentication. The method doesnot transmit the password in plaintext.

For more information, refer to the 4.0 or earlier version of themanual.mechanismstringOptional. 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 toauthenticate to the fromhost.