Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import example dataset (the system cannot find the specified file)

Tags:

mongodb

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?

like image 835
ericgrosse Avatar asked Feb 09 '23 13:02

ericgrosse


2 Answers

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.

like image 54
rajadilipkolli Avatar answered Feb 12 '23 01:02

rajadilipkolli


For Windows! Save file using notepad++ in .json format at MongoDB/bin where mongoimport command is present.

Simple notepad has trouble doing it.

like image 21
code_love Avatar answered Feb 12 '23 03:02

code_love