18

I'm trying to run mongorestore through docker to restore the database to another dockerized mongo on the system:

sudo docker run --net=host -v $PWD:/home/mongo mongo /bin/bash -c "mongorestore -d venko /home/mongo/mongo_venko_20200326230306.archive"

but I get

2020-03-27T00:17:32.645+0000    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
2020-03-27T00:17:32.645+0000    Failed: file /home/mongo/mongo_venko_20200326230306.archive does not have .bson extension
2020-03-27T00:17:32.645+0000    0 document(s) restored successfully. 0 document(s) failed to restore.

Answers from mongorestore error: Don't know what to do with the dump file tell me to pass the -db option but I did pass so I don't know what to do.

PPP
  • 1,279
  • 1
  • 28
  • 71
  • 26
    try passing the file with `--archive=` – Joe Mar 27 '20 at 01:43
  • 1
    @Joe it worked. Thanks. For anyone reading, this bash script restores a file from mongodump using docker: `sudo docker run --net=host -v $PWD:/home/mongo mongo /bin/bash -c "mongorestore --archive=/home/mongo/$1"` – PPP Apr 03 '20 at 06:44

3 Answers3

12

I have to use both options --gzip and --archive

mongorestore --uri="uri" --gzip --archive=/Path/to/archive/abc.gz
Bằng
  • 557
  • 6
  • 24
0

As the error mentions the mongorestore looks for a BSON file, while the archive is not the extension it is looking for.

You can do the following:

  1. Either use:

    mongorestore --gzip /home/mongo/mongo_venko_20200326230306.archive

  2. Or, Extract the archive file and use:

    mongorestore /home/mongo/mongo_venko_20200326230306/<filename.bson>

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 28 '22 at 07:26
0

Use the following command

mongorestore --archive=<path to *.archive> <database name>

for instance

mongorestore --archive=/home/mmroshani/mongo_gps_mongo_20230405-130054.archive gps

The correct output is kinda like

...

2023-04-07T14:01:18.397+0330    26868024 document(s) restored successfully. 0 document(s) failed to restore.

This fixed the issue and worked well, hope it helps and thanks for your consideration.

mmRoshani
  • 99
  • 7