Upload Data into MongoLab database from terminal

Viewed 3431

I'm having trouble figuring out how to upload csv data to my MongoLab database. From my terminal I have used

sudo mongoimport --db heroku_hkr86p3z -u <dbusername> -p <dbpassword> --collection contributors --type csv --headerline --file /Users/tonywinglau/Desktop/independent-expenditure.csv 

and

sudo mongoimport --host mongodb://<username>:<password>@ds035310.mlab.com:35310/heroku_hkr86p3z --db heroku_hkr86p3z -u <username> -p <password> --collection contributors --type csv --headerline --file /Users/tonywinglau/Desktop/independent-expenditure.csv 

both of which respond with

Failed: error connecting to db server: no reachable servers
imported 0 documents

From what I have read it might be something to do with my 'mongo config' file (I can't find it if it does exist) being set to only connect with localhost? How do I import data directly into my mongolab hosted database?

1 Answers

Your command line should look like this:

mongoimport -d <databasename> -c <collectionname> --type csv --file <filelocation/file.csv> --host <hostdir example:ds011291.mlab.com> --port <portnumber example:11111> -u <username> -p <password> --headerline

The host direction and the port number it gived by mlab when you create the database. Example:

ds000000.mlab.com:000000/databaseName
Related