In the first of many posts to simplify connecting to MongoHQ, we’re providing sample code for many programming languages, frameworks and setups (replica sets, slaveOk, etc).
These examples all assume that your MongoHQ connection string is set in an environment variable MONGOHQ_URL, like this:
If you use any of our PaaS providers this environment variable should already be set when you choose the MongoHQ add-on. Or you can set it yourself using whatever mechanism the Paas allows. For example, in Heroku:
heroku config:add MONGOHQ_URL=mongodb://...
PHP Connection to MongoHQ
sudo pecl install mongo
npm install mongodb
NodeJS Connection to MongoHQ (CoffeeScript)
(Side note… I love coffeescript)
Ruby Connection to MongoHQ
We wrap up today by connecting Ruby to MongoHQ. To get started, install the
mongo gem. If you want more speed, install the native
bson_ext, and if you are in less than Ruby 1.9, you’ll need the
json gem. It should go without saying, but you will need RubyGems.
gem install mongo bson_ext json
Part 2 will be Python and Java, and maybe more.