Deprecated since version 3.0.Important
Starting in version 4.2, MongoDB removes the
evalcommand. The deprecated
db.collection.copyTo(), which wraps the
evalcommand, can only be run against MongoDB 4.0 or earlier versions. For behavior and example, refer to the 4.0 or earlier version of the manual.
Copies all documents from
newCollectiondoes not exist, MongoDB creates it.ParameterTypeDescription
newCollectionstringThe name of the collection to write data to.
db.collection.copyTo()returns the number of documents copied. If the copy fails, it throws an exception.