Reputation: 1510
I am following the example given on MongoDB's website here, but I am running into trouble when trying to import sample data.
When running the command
mongoimport --db test --collection restaurants --drop --file primer-dataset.json
I get the error:
Failed: open primer-dataset.json: The system cannot find the file specified
The problem is, I am not sure what directory MongoDB expects this file to be in. I tried placing it in data/db, but that did not work. Note that I am only using default settings.
I know this is a somewhat trivial question and I feel stupid for asking it but I can not find documentation on this anywhere. Where is MongoDB expecting import files?
Upvotes: 4
Views: 9479
Reputation: 11
It happened to me as well. The issue was that though the file was visible as restaurants.json actually the file was restaurants.json.json (since saved in JSON format). The issue was resolved after properly changing the name.
Upvotes: 1
Reputation: 1
you must copy your json file into C:\Windows\System32 and write this command on cmd: mongoimport --db test --collection mongotest --type json --file yournamefile.json
Upvotes: 0
Reputation: 1
In my case, I removed the --drop
parameter and it worked perfectly. I guess, it is throwing this error:
Failed: open paht/file-name.json: The system cannot find the file specified.
because the collection it wants to drop is not available, because I have not created any before.
Upvotes: 0
Reputation: 3601
MongoDB expects the file to be in the directory from where you are running the command mongoimport.
If you place your file under data/db then set mongodb path as global environment variable and execute the command from data/db directory.
Additionally if you have security enabled for your mongodb then you need to execute command as below
mongoimport --username admin --password password --db test --collection restaurants --drop --file primer-dataset.json
here admin is the user authorized to perform db operations for test database and restaurants is the collection name.
Upvotes: 6
Reputation: 1
Check the filename extension, and make sure it's a ".json" file; After this I successfully run the
mongoimport --db test --collection restaurants --drop --file [path\to\Json file]
command;
Upvotes: 0
Reputation: 2354
i have trouble like you, check you path to file, mongoimport.exe and your file may be stay in another folders.
use mongoimport -d test1 -c restaraunts companies.json
for import to mongodb.
Upvotes: 0
Reputation: 116
For Windows! Save file using notepad++ in .json format at MongoDB/bin where mongoimport command is present.
Simple notepad has trouble doing it.
Upvotes: 2