How to export all collections in MongoDB?

前端 未结 28 1550
你的背包
你的背包 2020-11-29 14:32

I want to export all collections in MongoDB by the command:

mongoexport -d dbname -o Mongo.json

The result is:
No collection specifie

28条回答
  •  再見小時候
    2020-11-29 15:03

    If you're dealing with remote databases you can try these commands given that you don't mind the output being BSON

    1. Dump out as a gzip archive

    mongodump --uri="mongodb://YOUR_USER_ID:YOUR_PASSWORD@YOUR_HOST_IP/YOUR_DB_NAME" --gzip --archive > YOUR_FILE_NAME
    

    2. Restore (Copy a database from one to another)

    mongorestore --uri="mongodb://$targetUser:$targetPwd@$targetHost/$targetDb" --nsFrom="$sourceDb.*" --nsTo="$targetDb.*" --gzip --archive
    

提交回复
热议问题