db.collection.copyTo()
Definition
mongo
Shell Method
This page documents the mongo
shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.
Deprecated since version 3.0.
Important
Starting in version 4.2, MongoDB removes the eval
command.The deprecated db.collection.copyTo()
, which wraps theeval
command, can only be run against MongoDB 4.0 or earlierversions. For behavior and example, refer to the 4.0 or earlierversion of the manual.
Copies all documents from collection
into newCollection
usingserver-side JavaScript. If newCollection
does not exist, MongoDBcreates it.
ParameterTypeDescriptionnewCollection
stringThe name of the collection to write data to.
db.collection.copyTo()
returns the number of documentscopied. If the copy fails, it throws an exception.