Chris Mendez in For Developers, Openshift, MongoDB

Import JSON data to MongoDB on OpenShift

You will need a few things to get this project started. First you will need a JSON file, an account with Openshift as well as MongoDB and MongoRock.

Prepare

Make sure your JSON data is delineated by \n. This example file contains coordinates for the national parks within the U.S.

Upload

You will need to use scp to upload your JSON file to your server. Openshift only allows you to upload data to app-root/data. You will get the path to your sever from within the Openshift dashboard.

scp path/to/myfile.json 000xxxxxxxxxxxx000@myapp-mynamespace.rhcloud.com:app-root/data  

Log in

The next step is to SSH into your server

ssh 000xxxxxxxxxxxx000@myapp-mynamespace.rhcloud.com  

Publish

You upload the JSON file from your server to MongoDB using mongoimport

mongoimport --host 127.x.xx.xxx --db mydb -collection my-collection --username admin --password XXXXXXX --type json --file app-root/data/myfile.json  

Review

Double check your work using MongoRock.

https://myapp-mynamespace.rhcloud.com/rockmongo/index.php?action=admin.index  

TA DA!

You're done!


Resources