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

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

Is there a simple way to do this?

19条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 01:03

    This won't solve your problem but the mongodb shell has a copyTo method that copies a collection into another one in the same database:

    db.mycoll.copyTo('my_other_collection');
    

    It also translates from BSON to JSON, so mongodump/mongorestore are the best way to go, as others have said.

提交回复
热议问题