Mongodb: db.collection.copyTo() and eval() have been deprecated. What's the alternatives?

后端 未结 3 1252
猫巷女王i
猫巷女王i 2021-02-07 02:44

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?

相关标签:
3条回答
  • 2021-02-07 02:57

    For a server-side solution you can use aggregation...

    db.getCollection('source')
        .aggregate([
            { $out: 'destination' }
        ]);
    
    0 讨论(0)
  • 2021-02-07 03:05

    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
    
    0 讨论(0)
  • 2021-02-07 03:07

    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

    0 讨论(0)
提交回复
热议问题