How to copy a collection from one database to another in MongoDB

前端 未结 19 1576
無奈伤痛
無奈伤痛 2020-11-28 00:22

Is there a simple way to do this?

19条回答
  •  余生分开走
    2020-11-28 01:07

    You can use aggregation framework to resolve your issue

    db.oldCollection.aggregate([{$out : "newCollection"}])
    

    It shoul be noted, that indexes from oldCollection will not copied in newCollection.

提交回复
热议问题