MONGOIMPORT : no such file or directory for JSON file

308 Views Asked by At

I am trying to run this mongo import command, and this was working fine until yesterday, but now all I get is no such file or directory, I keep on copying the absolute path and it still doesn't work can anyone please help me

This is the import statement: mongoimport --db mydb_backup --collection extra_data --file “/Users/muskanmall/PycharmProjects/BD_HOMEWORK6/updateddata.json” --drop

additionally I also tried moving the file elsewhere and still the same issue: this is the import statement for that: mongoimport -d mydb_backup -c extra_data --type JSON --file “/Users/muskanmall/Desktop/updateddata.json”

This is the error I am getting: Failed: open “/Users/muskanmall/Desktop/updateddata.json”: no such file or directory 2023-03-31T12:41:12.179-0400 0 document(s) imported successfully. 0 document(s) failed to import.

I tried to import it and I got this error, does anyone know why I am facing this issue or does anyone know what I am doing wrong and what would be a correction

2

There are 2 best solutions below

0
MuskanMall On

I found the solution, I thought I will still keep the question incase someone else faces this issue and I didn't find any matching question.

So the reason this was not working was because my collection name was extra_data, it had a _ in between, which was causing the issue so this is the corrected command

mongoimport --db mydb_backup --collection extradata --file '/Users/muskanmall/Desktop/updateddata.json' --drop

Another issue in MAC is using double quotes, sometimes Mac can't recognize double quotes, so put your pathing single quotes Ideally dont have any special characters in any of the names Hope it helps!

0
Hassan A On

I had a similar issue in Ubuntu, where I was getting an error stating that " Failed: open fileName.json: no such file or directory" my solution was to create the json file first by running

touch fileName.json

then running the mongoimport command with the required arguments. for example:

mongoimport --host 'localhost' --port '27017' --db 'your_database_name' --collection 'your_collection_name' --file 'fileName.json' make sure to use single quotes in Ubuntu.