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 deprecateddb.copyDatabase()
, which wraps thecopydb
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 and Clone Databases.
Copies a database either from one
mongod
instance to the currentmongod
instance or within the currentmongod
.The
mongosh
helper methoddb.copyDatabase()
takes the following arguments:ParameterTypeDescriptionfromdb
stringName of the source database.todb
stringName of the target database.fromhost
stringusername
stringOptional. The name of the user on the
fromhost
MongoDB instance. The user authenticates to thefromdb
.For more information, refer to the 4.0 or earlier version of the manual.
password
stringOptional. 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
stringOptional. The authentication mechanism on the
fromhost
.The
fromhost
credentials must use SCRAM-SHA-1.Changed in version 4.0:
db.copyDatabase()
no longer supportsMONGODB-CR
to authenticate to thefromhost
.