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?
In MongoDB, copyTo() method is used to copies all the documents from one collection(Source collection) to another collection(Target collection) using server-side JavaScript and if that other collection(Target collection) is not present then MongoDB creates a new collection with that name.
The save() returns a WriteResult() object that contains the status of the insert or update operation.
For a server-side solution you can use aggregation...
db.getCollection('source') .aggregate([ { $out: 'destination' } ]);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With