How to import collection from MongoDB to mLab?

How to import collection from MongoDB to mLab?
0

#1

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?


#2

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 ds012345.mlab.com:56789 -d dbname -c collectionname -u dbuser -p dbpassword --file filename.json

#3

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 gave by mlab when you create the database. Example:

ds000000.mlab.com:000000/databaseName