Amanjot
Amanjot

Reputation: 2048

Mongodb CSV functionality not working

 mongoimport -d  ramp -c country --type csv --file http://fromtheramp.com/temp/country.csv --headerline

I had use import funtionality on localhost and is working fine. but now, it is not working on server. it gives me the following error.

Failed: open http://fromtheramp.com/temp/country.csv: no such file or directory

http://fromtheramp.com/temp/country.csv file exists but is not getting imported.

Upvotes: 1

Views: 133

Answers (1)

Blakes Seven
Blakes Seven

Reputation: 50416

The mongoimport utility does not work with external file sources such as a URI resource like you are trying to do.

In order to do what you want, "pipe" the input from another command like curl to mongoimport instead:

curl http://fromtheramp.com/temp/country.csv | \
mongoimport -d  ramp -c country --type csv --headerline

Both mongoimport and mongoexport both work with STDIN/STDOUT as default unless you include an option such as --file. So omit that and work with STDIN instead.

As a non-csv example ( same principles apply though ) you can use the publicly accessible mongodb sample data set as a test:

curl https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/dataset.json | \
mongoimport -d test -c restaurants --drop

Which hapilly imports that data, and a bit more effienctly than the manual page suggests you do it. Though you might want a local copy for testing.

Upvotes: 2

Related Questions