MongoLab

MongoLab Partner JavaScript

Deploy

This git repository demonstrates how to use MongoLab on OpenShift using Node.

Once you've created the quickstart, you'll need to create a MongoLab account and add your authorization information to your Git repository. Making code changes will require you to set a public SSH key, and then to clone your new application Git repository onto your local machine. See the Getting Started page for more steps in this flow.

Step 1. Create a MongoLab Account and Database

  1. Sign up for an account at http://www.mongolab.com. When successful, a database landing page with no databases displays.
  2. Create a database. Be sure to specify a database user name and password. These credentials are not the same as your MongoLab account credentials.
  3. Click on your database. The database landing page provides a mongodb URI connection string of the form:
    mongodb://<user>:<password>@host.mongolab.com:12345/my-db-name
  1. Copy this value somewhere helpful and replace placeholders with your database user credentials.

Step 2. Deploy your app

    git add .
    git commit -m "my first commit"
    git push

Step 3. Configure environment variables on the app gear

The example code uses mongodb://localhost:27017/test when the MONGOLAB_URI environment variable is not available. This is sufficient for testing locally with your own mongodb, but not for production.

Note: We find that configuring this value outside of the code (and not storing it in a repository) allows for maximum security and flexibility. However, there are repository-driven alternatives for configuring this environment variable that may meet your requirements. See how to create and use environment variables on the server for more information.

To configure your environment variable without placing credentials in a repository:

  1. Login to http://openshift.redhat.com
  2. Click My Apps.
  3. Click the > next to your app name to reach your application page.
  4. Click Want to log in to your application?
  5. Copy the provided ssh shell command to a shell window and press enter to ssh to your app gear.
  6. Open your gear's .bash_profile in your text editor of choice. It is located at ~/app-root/data/.bash_profile.
  7. Add the line export MONGOLAB_URI=<db uri> where db uri is the mongodb URI you obtained in Step 2, with your database user credentials added.
  8. After editing the file, run source ~/app-root/data/.bash_profile
  9. Use echo $MONGOLAB_URI to confirm success. The value you added should be displayed at the console.
  10. Restart your app by running ctl_all stop then ctl_all start.

Step 4. View your app!

    http://$appname-$yournamespace.rhcloud.com

More Information

Email support@mongolab.com

Author
mongolab
Documentation
https://github.com/mongolab/mongolab-openshift-quickstart
Website
https://mongolab.com/welcome/
Cartridges
nodejs-0.6
Repository
https://github.com/mongolab/mongolab-openshift-quickstart
Tags