How do I create a MongoDB dump of my database?

前端 未结 19 2388
既然无缘
既然无缘 2020-12-22 15:06

What command do I use and run?

相关标签:
19条回答
  • 2020-12-22 15:56

    cmd -->

    C:\Program Files\MongoDB\Server\3.2\bin>mongodump.exe --db Dintest
    
    0 讨论(0)
  • 2020-12-22 15:57

    You need to open command prompt as an administrator in a folder where your Mongo is installed (in my case: C:\Program Files\MongoDB\Server\3.4\bin). If you want to dump your whole database, you can just use:

    mongodump --db database_name
    

    You also have posibilities to dump only certain collection(s), or to dump all but certain collection(s).

    If you want to dump only one collection (for example users):

    mongodump  --db database_name --collection users
    

    If you want to dump all but users collection:

    mongodump  --db database_name --excludeCollection=users
    

    It is also possible to output the dump to an archive file:

    mongodump --archive=test.archive --db database_name
    
    0 讨论(0)
  • 2020-12-22 15:58

    To dump your database for backup you call this command on your terminal

    mongodump --db database_name --collection collection_name
    

    To import your backup file to mongodb you can use the following command on your terminal

    mongorestore --db database_name path_to_bson_file
    
    0 讨论(0)
  • 2020-12-22 15:58

    Below command will work to take dump of mongo db .

    mongodump -d -o

    On Windows : try this one where c:\mongodump is dump file location , It will create metadata in json, and backup in bson format

    C:\MongoDB\bin>mongodump -d -o c:\mongodump

    0 讨论(0)
  • 2020-12-22 16:00

    If your database in the local system. Then you type the below command. for Linux terminal

    mongodump -h SERVER_NAME:PORT -d DATABASE_NAME
    

    If database user and password are there then you below code.

    mongodump -h SERVER_NAME:PORT -d DATABASE_NAME -u DATABASE_USER -p PASSWORD
    

    This worked very well in my Linux terminal.

    0 讨论(0)
  • 2020-12-22 16:01
     Use -v to see progress of backup data
        mongodump -v --db dbname --out /pathforbackup/NewFolderforBackupData
    
     you can use it for restore also
        mongorestore -v --db dbname --drop /pathforbackup/NewFolderforBackupData/dbname
    
    with multile v like -vvvv you will get more information
    
    0 讨论(0)
提交回复
热议问题