142

I have mongo DB installed in the following path c:\mongodb\bin. I have configured my environment variable PATH in advanced settings.I also have mongod running .When I run the following command mongorestore dump from the following path c:\hw1-1\dump (This contains the BSON files) I'm getting this error:

Don't know what to do with the dump file

I have referred to this thread to check my path.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Prasanna Aarthi
  • 3,439
  • 4
  • 26
  • 48
  • All the answers are different because all this error really means is that some of your flags are incorrect. Which flags are incorrect will depend on what your restoring and where your restoring it. Use `mongodump --help` to get a list of the current flags on your instance to debug this issue. – Liam Mar 29 '17 at 08:55

7 Answers7

349

in mongodb 3.0 or above, we should specify the database name to restore

mongorestore -d [your_db_name] [your_dump_dir]
clevertension
  • 6,929
  • 3
  • 28
  • 33
  • I am using windows version 3.0.3 and specifying the database name did it for me!Thank you @clevertension. – Sotiris Zegiannis Jun 01 '15 at 10:59
  • Worked like a charm on 3.0.6 too. – sharmaap Oct 29 '15 at 15:34
  • This was the issue I had after upgrading `mongodb-tools`, thanks! – emyller May 04 '16 at 12:39
  • 2
    This worked for me using authentication like so: `mongorestore -u k00k -p 1337p455w0rd -d mydb ./dump/mydb` – k00k Jul 19 '16 at 11:53
  • 2
    This is an old answer. In newer versions you cannot specify the `--db` (`-d`) parameter in many cases. This is how I restore it currently: `mongorestore --nsFrom=fromdbname.* --nsTo=todbname.* yourdumpfolder/` Furtherly when you used gzip you need to provide the `--gzip` parameter and if you want to override stuff you can add the `--drop` parameter. – Jos Nov 27 '19 at 11:45
  • 1
    mongorestore mongodb://user:password@127.0.0.1:27017/ dump/ Folder structure should be /dump/ .json .bson – Sukesh Ashok Kumar Aug 08 '22 at 14:42
38

You probably saw this error:

ERROR: don't know what to do with file [dump]

Which means in this case, that there is no file or directory called dump in your current working directory. So, Try this first cd c:/hw1-1/ (or whatever the correct syntax is on Windows, I can't test it.) Alternatively you can specify the full path to the dump directory:

mongorestore c:/hw1-1/dump
shA.t
  • 16,580
  • 5
  • 54
  • 111
Mzzl
  • 3,926
  • 28
  • 39
9

If you're using mongoexport to create the dump, be sure to use mongoimport rather than mongorestore to load it.

punkrockpolly
  • 9,270
  • 6
  • 36
  • 37
6

This error message "don't know what to do with file" can also occur if you have a BSON file that does not have a .bson file extension.

Generally this isn't a problem since mongodump generates the files with .bson extensions, but in my case I had a BSON file that was not generated by mongodump and had a different file extension.

helmy
  • 9,068
  • 3
  • 32
  • 31
5

I'm on version 3.2 windows and my mongorestore seems to have a bug:

If I specify /db:database_name or /d database_name I get the error:

don't know what to do with subdirectory "dump\database_name", skipping...

Instead if I let it run on the whole dump directory it seems to work. The command I used is:

mongorestore /host:remote_host dump

My current directory structure is:

.
..
dump
dump\database_name
Pooya
  • 6,083
  • 3
  • 23
  • 43
Anton Wolkov
  • 163
  • 2
  • 10
1

I got this error when I had a collection matching the name of the one I was trying to restore present in Mongo ended up going into Mongo and deleting it using db.m101.drop();

Donovan Thomson
  • 2,375
  • 3
  • 17
  • 25
-1

It took me some time to figure out the options for mongorestore , after i had kept getting this error for some time .

a) No running instances of mongod .

b) mongorestore -v -host localhost:27017 --dbpath "Actual Path for the Mongo DB- set in config" "Location where the dump is"

Using dbpath , allows to run this command without any running version of mongod . And this resolved my error .

Roshan Khandelwal
  • 953
  • 1
  • 11
  • 17