MongoDb: How to import dump data from .gz file?

Chaitanya Parashar picture Chaitanya Parashar · Oct 31, 2018 · Viewed 22.6k times · Source

I want to import dump data from my .gz file.

Location of file is home/Alex/Documents/Abc/dump.gz and the name of db is "Alex".

I have tried mongorestore --gzip --db "Alex" /home/Alex/Documents/Abc/dump.gz

But it shows error:

 2018-10-31T12:54:58.359+0530   the --db and --collection args should 
 only be used when restoring from a BSON file. Other uses are 
 deprecated and will not exist in the future; use --nsInclude instead
 2018-10-31T12:54:58.359+0530   Failed: file 
 /home/Alex/Documents/Abc/dump.gz does not have .bson extension.

How can I import it?

Answer

Hardik Shah picture Hardik Shah · Oct 31, 2018

Dump command:

mongodump --host localhost:27017 --gzip --db Alex --out ./testSO

Restore Command:

mongorestore --host localhost:27017 --gzip --db Alex ./testSO/Alex

Works perfectly!


While using archive:

Dump command:

mongodump --host localhost:27017 --archive=dump.gz --gzip --db Alex

Restore Command:

mongorestore --host localhost:27017 --gzip --archive=dump.gz --db Alex

Note:- While using archive you need to stick with the database name.

Different database name or collection name is not supported. For more info.