- Reference >
mongo
Shell Methods >- Database Methods >
- db.copyDatabase()
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/Clone a Database.
Copies a database either from one
mongod
instance to the currentmongod
instance or within the currentmongod
.The
mongo
shell methoddb.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 samemongod
instance.username
string Optional. 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
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 supportsMONGODB-CR
to authenticate to thefromhost
.