copyTo( newCollection )
Deprecated since version 3.0.
Copies all documents from
newCollectiondoes not exist, MongoDB creates it.
If authorization is enabled, you must have access to all actions on all resources in order to run
db.collection.copyTo(). Providing such access is not recommended, but if your organization requires a user to run
db.collection.copyTo(), create a role that grants
anyActionon anyResource. Do not assign this role to any other user.
Parameter Type Description
string The name of the collection to write data to.
db.collection.copyTo()method uses the
evalcommand internally. As a result, the
db.collection.copyTo()operation takes a global lock that blocks all other read and write operations until the
copyTo() returns the number of documents copied. If the copy fails, it throws an exception.