- Reference >
mongoShell 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
copydbcommand. The deprecateddb.copyDatabase(), which wraps thecopydbcommand, 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
mongodinstance to the currentmongodinstance or within the currentmongod.The
mongoshell methoddb.copyDatabase()takes the following arguments:Parameter Type Description fromdbstring Name of the source database. todbstring Name of the target database. fromhoststring Optional. The hostname of the source mongodinstance. Omit to copy databases within the samemongodinstance.usernamestring Optional. The name of the user on the
fromhostMongoDB instance. The user authenticates to thefromdb.For more information, refer to the 4.0 or earlier version of the manual.
passwordstring Optional. The password on the
fromhostfor authentication. The method does not transmit the password in plaintext.For more information, refer to the 4.0 or earlier version of the manual.
mechanismstring Optional. The authentication mechanism on the
fromhost.The
fromhostcredentials must use SCRAM-SHA-1.Changed in version 4.0:
copyDatabase()no longer supportsMONGODB-CRto authenticate to thefromhost.