mongodbmongoimport

mongoimport for csv: "no such file or directory"; "imported 0 documents"


I'm trying to import a .csv file full of data into mongo on OSX. I'm opening a terminal, running mongod and then opening a new terminal window and running the following command

Scotts-MacBook-Air:~ scott$ mongoimport --db myDbName --collection myCollectionName --type csv --headerline --file /Desktop/info.csv

I've tried it many different times but am always getting the following response:

2019-02-11T19:16:04.904-0600 Failed: open /Desktop/info.csv: no such file or directory 2019-02-11T19:16:04.905-0600 imported 0 documents

The document is saved as Windows comma separated (.csv) format on my desktop.

Can anyone help me understand how I can get this to be accepted by mongo?


Solution

  • You specified the file as /Desktop/info.csv, which means that you told mongoimport to look for the file under a /Desktop folder that resides under the root directory.

    I don't think this is what you intended.

    Changing /Desktop/info.csv to ~/Desktop/info.csv should fix it.