Search code examples
mongodbmongodumpmongorestore

Restore mongodump database backup, which is the right flow?


I'm performing my first steps with MongoDB but still lost. I have read the docs here but I'm not able to find the the right steps in order to import|restore the DB. I have a .tgz file and I have uncompressed it. The output of ll command is as follow:

# ll rs-ds035698_2015-09-21T050031.000Z
total 208
drwxr-xr-x 2 1001 1001   4096 Sep 21 01:00 admin
-rw-r--r-- 1 1001 1001   1037 Sep 21 01:01 oplog.bson
drwxr-xr-x 2 1001 1001  20480 Sep 21 01:01 pdone
drwxr-xr-x 2 1001 1001  20480 Sep 21 01:01 pdone_demo
drwxr-xr-x 2 1001 1001   4096 Sep 21 01:00 pdone_demo_master
drwxr-xr-x 2 1001 1001   4096 Sep 21 01:01 pdone_master
-rw-r--r-- 1 1001 1001 150589 Sep 21 01:01 rs-ds035698_2015-09-21T050031.000Z.log

I need to restore just pdone database. How?


Solution

  • Maybe it will helpful to you....

    $mongorestore (It will restore all databases from your dump folder)
    

    Restore particular database from your "dump" folder :

    $mongorestore --db employee  C:\Users\mongo\dump\employee (Here "employee" is new db name)
    

    if you want to import an JSON file then follow this :

    mongoimport -d students -c grades < grades.json
                         (or)    
    mongoimport -d students -c grades < C:\Users\mongo\Download\grades.json
    
    Note: here "students" is database name, "grades" is collection name.