What's the fastest way to copy a collection within the same database?

后端 未结 8 645
余生分开走
余生分开走 2020-11-30 19:01

I want to copy a collection within the same database and give it a different name - basically take a snapshot.

What\'s the best way to do this? Is

相关标签:
8条回答
  • 2020-11-30 19:32

    In addition to AD7six 1st solution, if you use mongoexport / import be sure about your collection data types and mongo configuration, as explained here: http://docs.mongodb.org/manual/reference/mongodb-extended-json/

    0 讨论(0)
  • 2020-11-30 19:34
    db.myoriginal.aggregate([ { $match: {} }, { $out: "mycopy" } ])
    

    It is a lot faster than doing many inserts in a forEach loop.

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