How to import collection from MongoDB to mLab?

Title says it all, I would like to import my collection from my local db to the cloud, I’ve tried reading the documentation but it’s not very clear as in which folder I’m supposed to run the commands in the terminal.

Also, can I connect my db to the cloud in my node app?, if so, how?

I was able to do it, I’m going to leave the solution here as a reference in case someone needs help with this

mongoimport -h -d dbname -c collectionname -u dbuser -p dbpassword --file filename.json
1 Like

Your command line should look like this:

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

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

Thanks! That worked for me