I find that db.collection.copyTo() and eval() have been deprecated since 3.0. But I do not find what can be instead.
What\'s the alternatives?
For a server-side solution you can use aggregation...
db.getCollection('source')
.aggregate([
{ $out: 'destination' }
]);
Create a mongodump of that collection, do mongorestore to a separate or new collection.
This wont stop read/write or wont lock the collection.
mongodump --db db-name --collection collection-name --archive=collection-name.archive
or save as json both works
If saved as archive, to restore
mongorestore --db db-name --collection collection-name --archive=collection-name.archive
Per this discussion on the MongoDB Group.
The alternative is to implement the equivalent queries/operations using the normal MongoDB query language and client driver API
So that would mean writing your queries in a client environment (e.g. Node.js) and execute them that way. If run on the server connecting to localhost, they should pretty quick, although probably not as quick as using eval.
The rationale for the being deprecated is outlined in this ticket. https://jira.mongodb.org/browse/SERVER-17453