How to export all collections in MongoDB?

前端 未结 28 1526
你的背包
你的背包 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:05

    Follow the steps below to create a mongodump from the server and import it another server/local machine which has a username and a password

    1. mongodump -d dbname -o dumpname -u username -p password
    2. scp -r user@remote:~/location/of/dumpname ./
    3. mongorestore -d dbname dumpname/dbname/ -u username -p password
    
    0 讨论(0)
  • 2020-11-29 15:05

    In case you want to connect a remote mongoDB server like mongolab.com, you should pass connection credentials eg.

    mongoexport -h id.mongolab.com:60599 -u username -p password -d mydb -c mycollection -o mybackup.json
    
    0 讨论(0)
  • 2020-11-29 15:08

    Previous answers explained it well, I am adding my answer to help in case you are dealing with a remote password protected database

    mongodump --host xx.xxx.xx.xx --port 27017 --db your_db_name --username your_user_name --password your_password --out /target/folder/path
    
    0 讨论(0)
  • 2020-11-29 15:09
    #mongodump using sh script 
    #!/bin/bash
    TIMESTAMP=`date +%F-%H%M`
    APP_NAME="folder_name"
    BACKUPS_DIR="/xxxx/tst_file_bcup/$APP_NAME"
    BACKUP_NAME="$APP_NAME-$TIMESTAMP"
    /usr/bin/mongodump -h 127.0.0.1 -d <dbname> -o $BACKUPS_DIR/$APP_NAME/$BACKUP_NAME
    tar -zcvf $BACKUPS_DIR/$BACKUP_NAME.tgz $BACKUPS_DIR/$APP_NAME/$BACKUP_NAME
    rm -rf /home/wowza_analytics_bcup/wowza_analytics/wowza_analytics
    ### 7 days old backup delete automaticaly using given command
    
    find /home/wowza_analytics_bcup/wowza_analytics/ -mindepth 1 -mtime +7 -delete
    
    0 讨论(0)
提交回复
热议问题