Mongodb: db.collection.copyTo() and eval()

2019-01-24 02:24发布

问题:

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?

回答1:

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



回答2:

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



标签: mongodb