0

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?

ReynierPM
  • 17,594
  • 53
  • 193
  • 363

2 Answers2

2

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.
Nani
  • 446
  • 7
  • 24
  • I must doing something wrong, didn't work for me: `$mongorestore --db rs-ds035698_2015-09-21T050031.000Z/pdone connected to: 127.0.0.1 don't know what to do with file [dump]` – ReynierPM Sep 21 '15 at 14:53
  • But `mongoimport` seems to be file by file and DB has a lot of collections or I am wrong? – ReynierPM Sep 21 '15 at 15:08
  • the file your trying to import is in .json format or not...? @ReynierPM – Nani Sep 21 '15 at 15:09
  • Was my bad *I need to restore just pdone database* I've fixed the main post, is the complete DB not a collection – ReynierPM Sep 21 '15 at 15:10
  • Sorry dude i can't get you............ if "pdone" is ur database folder then try this..... mongorestore --db . Eg:(mongorestore --db pdone /home/nani/Desktop/pdone) @ReynierPM – Nani Sep 22 '15 at 07:51
0

Following command is useful for restoring mongodump BSON file. In my case it is user.bason file

sudo mongorestore -d ibfs -c log /opt/backup/mongodump-2017-02-01/ibfs/user.bson

Explaination :

sudo mongorestore -d ibfs(DATABASE_NAME) -c log(COLLECTION_NAME) /opt/backup/mongodump-2017-02-01/ibfs/user.bson(WHOLE PATH)
MAULIK MODI
  • 592
  • 6
  • 10