MongoHQ

MongoHQ

Last modified by Spike Washburn on 2014/06/04 20:02

MongoHQ is a CloudBees Ecosystem partner who provides the hosted database solution for getting your applications up and running on MongoDB. By subscribing to this service on the ecosystem page, you can easily create and configure MongoDB databases as the data layer for your Cloudbees-hosted applications.

Subscribing to MongoHQ

You can subscribe to MongoHQ by reviewing the Ecosystem dialog clicking the MongoHQ icon, and clicking the subscribe button.  Please note that the MongoHQ base subscription is purely on-demand, so there is no cost for subscribing and you will be charged later if you create any upgraded MongoDB instances. 

MongoHQ Management Interface

After subscribing to MongoHQ, you can click the MongoHQ icon in the CloudBees Ecosystem dialog to create and manage the MongoDB instances attached to your account.

How to upgrade or downgrade MongoDB instance

You can upgrade your MongoDB instance from MongoDB management interface. Click on Edit button on your MongoDB resource to upgrade or downgrade its plan.

Creating a MongoDB instance

To create a new MongoHQ instance, click the "Add Resource" button on the MongoHQ management interface.

Using a MongoDB instance from your application

The MongoDB management interface displays list of your MongoDB databases. As a quick way to get started, you can click on Show config link and then copy MongoHQ_URL into your application code.  However, the preferred way to access the MongoHQ_URL when deploying to RUN@cloud is to use the Bees SDK app:bind command:

bees app:bind  -a <YOUR_APP>   -r mongohq:<MONGOHQ_RESOURCE>   -as <ALIAS>

That will automatically create a configuration parameter (called MONGOHQ_URL_<ALIAS>) that you can reference from your application.  For example, assuming my MongoHQ resource is called "gasp" and my app is called "gasp-mongo", then the following command will create a binding with alias "GASP", and a corresponding environment variable MONGOHQ_URL_GASP with the MongoHQ connection string:

bees app:bind -a gasp-mongo  -r mongohq:gasp -as GASP

If you aren't sure of the mongo databases available to your account, you can click through the console ecosystem link to mongohq to see them listed, or run: 

bees mongohq:list -a <ACCOUNT>

In some cases you may need to specify the account name as part of the binding: 

 bees app:bind -a <ACCOUNT>/<APP> -r mongohq:<ACCOUNT>/<mongodbname> -as <ALIAS>

eg:

 bees app:bind -a michaelnealemongo1/boobar -r mongohq:michaelnealemongo1/mydb1 -as MYMONGO

You can verify your configuration with the bees app:bindings and bees [SERVICE]:list commands, like so:

bees app:bindings -a gasp-mongo
bees mongohq:list

Now you can use e.g. System.getProperty("MONGOHQ_URL_GASP") to get the value of MONGOHQ_URL_GASP from the application's environment as described in this Configuration Parameters article.

Sample with the MongoDB Java Driver.

String uriAsString = System.getProperty("MONGOHQ_URL_GASP", "mongodb://localhost/local");
MongoClientURI uri = new MongoClientURI(uriAsString);
MongoClient mongoClient = new MongoClient(uri);
...
Tags:
Created by Spike Washburn on 2011/11/01 15:16