db.copyDatabase()
Definition
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 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:
ParameterTypeDescriptionfromdb
stringName of the source database.todb
stringName of the target database.fromhost
stringOptional. The hostname of the source mongod
instance. Omitto copy databases within the same mongod
instance.username
stringOptional. 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.password
stringOptional. 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.mechanism
stringOptional. 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
.