On this page本页内容
db.collection.
copyTo
(newCollection)¶mongo
Shell Method
This page documents the 本页记录了mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. mongo
shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。
Deprecated since version 3.0.自3.0版以来已弃用。
Important重要的
Starting in version 4.2, MongoDB removes the 从4.2版开始,MongoDB删除了eval
command. eval
命令。The deprecated 不推荐使用的db.collection.copyTo()
, which wraps the eval
command, can only be run against MongoDB 4.0 or earlier versions. db.collection.copyTo()
封装了eval命令,只能在MongoDB 4.0或更早版本上运行。For behavior and example, refer to the 4.0 or earlier version of the manual.有关行为和示例,请参阅4.0或更早版本的手册。
Copies all documents from 使用服务器端JavaScript将所有文档从collection
into newCollection
using server-side JavaScript. collection
复制到newCollection
。If 如果newCollection
does not exist, MongoDB creates it.newCollection
不存在,MongoDB将创建它。
newCollection |
string |
db.collection.copyTo()
returns the number of documents copied. 返回复制的文档数。If the copy fails, it throws an exception.如果复制失败,它将抛出异常。