db.copyDatabase()

On this page本页内容

Definition定义

db.copyDatabase(fromdb, todb, fromhost, username, password, mechanism)

Deprecated since version 4.0.自版本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实例或在当前mongod内。

The mongo shell method db.copyDatabase() takes the following arguments:mongo shell方法db.copyDatabase()采用以下参数:

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. mongod实例的主机名。Omit to copy databases within the same mongod instance.如果忽略,则复制同一mongod实例中的数据库。
username string

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或更早版本的手册。

password string

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或更早版本的手册。

mechanism string

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中更改。copyDatabase() no longer supports MONGODB-CR to authenticate to the fromhost.不再支持MONGODB-CRfromhost进行身份验证。