mongo copy from one collection to another (on the same db)

后端 未结 7 581
暖寄归人
暖寄归人 2020-12-24 08:02

I have got mongo db called test and in this db two collections collection1 and collection1_backup. How to replace content of col

7条回答
  •  遥遥无期
    2020-12-24 08:25

    also usefull: to export collection to json file

    mongoexport --collection collection1_backup --out collection1.json
    

    to import collection from json file

    mongoimport --db test --collection collection1 --file collection1.json
    

    to import single collection from backup/dump file one need to convert *.bson file to *.json by using

    bsondump collection1_backup.bson > collection1_backup.json
    

提交回复
热议问题