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

37,184

Solution 1

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.

Solution 2

This is what worked for me in the latest versions (100.5.1) of mongodump.

mongorestore --uri=<CONNECTION_URI> --gzip --archive=<ARCHIVE_NAME> --nsFrom "<SOURCE_DB_NAME>.*" --nsTo "<DEST_DB_NAME>.*"
Share:
37,184

Related videos on Youtube

Chaitanya Parashar
Author by

Chaitanya Parashar

~Dream On~

Updated on July 09, 2022

Comments

  • Chaitanya Parashar
    Chaitanya Parashar almost 2 years

    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?

  • Santiago Bendavid
    Santiago Bendavid over 4 years
    "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;"
  • mmell
    mmell over 4 years
    I have json and bson files from dump. --gzip without --db failed for me.
  • Nishat
    Nishat about 4 years
    mongorestore --host localhost:27017 --gzip --archive=dump.gz --db Alex this command does not work for me. I am getting an error same as @SantiagoBendavid.
  • Metafaniel
    Metafaniel almost 4 years
    Just in case you're asking (like myself) 27017 is the default MongoDB port: docs.mongodb.com/manual/reference/default-mongodb-port/…
  • Pragyanshu Sharma
    Pragyanshu Sharma over 3 years
    mongorestore --gzip --archive=/path/to/file.gz --db works for me
  • gaurav arora
    gaurav arora about 3 years
    different db names are supported with nsTo and nsFrom parameter fields of mongorestore utility