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. 从4.2版开始,MongoDB删除了copydb命令。The deprecated db.copyDatabase(), which wraps the copydb command, can only be run against MongoDB 4.0 or earlier versions. 已弃用的db.copyDatabase()包装了copydb命令,只能在MongoDB 4.0或更早版本上运行。For behavior and examples, refer to the 4.0 or earlier version of the manual.有关行为和示例,请参阅4.0或更早版本的手册。

For an alternative in version 4.2+, see Copy/Clone a Database.有关4.2+版中的替代版本,请参阅复制/克隆数据库

Copies a database either from one mongod instance to the current mongod instance or within the current mongod.将数据库从一个mongod实例复制到当前mongod或当前mongo内。

The mongosh helper method db.copyDatabase() takes the following arguments:mongosh helper方法db.copyDatabase()接受以下参数:

Parameter参数Type类型Description描述
fromdbstringName of the source database.源数据库的名称。
todbstringName of the target database.目标数据库的名称。
fromhoststringOptional. 可选。The hostname of the source mongod instance. mongod实例的主机名。Omit to copy databases within the same mongod instance.省略以复制同一mongod实例中的数据库。
usernamestring

Optional. 可选。The name of the user on the fromhost MongoDB instance. fromhost MongoDB实例上的用户名称。The user authenticates to the fromdb.用户对fromdb进行身份验证。

For more information, refer to the 4.0 or earlier version of the manual.有关更多信息,请参阅4.0或更早版本的手册。

passwordstring

Optional. 可选。The password on the fromhost for authentication. fromhost上用于身份验证的密码。The method does not transmit the password in plaintext.该方法以明文形式传输密码。

For more information, refer to the 4.0 or earlier version of the manual.有关更多信息,请参阅4.0或更早版本的手册。

mechanismstring

Optional. 可选。The authentication mechanism on the fromhost.fromhost上的身份验证机制。

The fromhost credentials must use SCRAM-SHA-1.fromhost凭据必须使用SCRAM-SHA-1

Changed in version 4.0.在版本4.0中更改

db.copyDatabase() no longer supports MONGODB-CR to authenticate to the fromhost.不再支持MONGODB-CRfromhost进行身份验证。

←  db.commandHelp()db.createCollection() →