Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 911
Chaitanya Parashar Avatar asked Oct 31 '18 07:10

Chaitanya Parashar


People also ask

How do I restore a .GZ file in MongoDB?

You should just be able to do mongorestore --gzip <path to gzip folder). Side note you can use mongodump with --gzip option and it will compress it for you.

How do I import files into MongoDB?

To import JSON file you need to follow the following steps: Step 1: Open a command prompt and give command mongod to connect with MongoDB server and don't close this cmd to stay connected to the server. Step 2: Open another command prompt and run the mongo shell. Using the mongo command.


1 Answers

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.

like image 158
Hardik Shah Avatar answered Sep 17 '22 15:09

Hardik Shah