A couple facts about three cool technologies

The Unicorn Is Penned, Unicorn Tapestries, c. ...

Image via Wikipedia

  • node.js is a powerful way of writing backend code in JavaScript; why JavaScript? Because you have the kind of problem that benefits from asynchronous code (the average web app) and you like using the same  brain for backend and frontend work
  • mongoDB is an awesome NoSQL data store for objects. It is an especially great companion to JavaScript since its internal storage are JSON-objects. JSON has plays particularly well with JavaScript due to certain similarities (some even think the JSON language is a subset of JavaScript, although it’s not)
  • Heroku is the simplest way to deploy web apps. Originally designed for Ruby, it gained node.js support last spring/summer. There are alternatives, but heroku presents itself as a particularly good pick for various reasons (it feels right)

Combining these three technologies should be a walk in the park. The best thing since sliced bread and unicorn farts should rain down the heavens upon you for even thinking of using node.js, mongo and heroku in unison.

Not so much.

The culprit – the bleeding edge, baby!

Mongo’s only been widely-ish popular for a year, node.js still isn’t widely and Heroku is traditionally a RoR hosting environment so there are things that aren’t quite smooth yet.

Getting mongoDB support on Heroku means using an external party – what heroku calls an add-on – MongoHQ. It’s a mongoDB hosting provider that gives you access to a database and lets you loose.

But MongoHQ requires authentication.

My favourite mongoDB driver for node.js … doesn’t support authentication. At least it doesn’t support authentication easily, in fact it doesn’t support authentication so much that it isn’t officially documented. The only reference to getting this working is some guy’s blogpost from April 2011. This is an actively developed library by the way, the last commit to node-mongodb-native‘s github was yesterday.

Some say I should be using mongoose instead, but that would most likely require rewriting the whole application at this point. Not to mention I don’t like mongoose’s ORM-like approach because that’s just a little too SQL for my liking. Why would you force a traditional data store way of doing things onto something as refreshing as Mongo?

To make things worse, a while ago (about a year it seems), mongo introduced a new mongo:// url schema for connecting to their database … not even all the official drivers support it yet.

Don’t you just love the bleeding edge? Competing libraries, standards shifting under your feet and things never quite working out!

Enhanced by Zemanta
  • http://twitter.com/christkv Christian Kvalheim

    Hi I’m the writer of the mongodb driver. There is no reason why authentication should not work.  Here is an example below.

    https://github.com/christkv/node-mongodb-native/blob/master/test/admin_test.js#L98

    One of the big gotcha’s in mongo can be at what level you define the user in the db. at the db or admin db level. the example above uses the admin db to authenticate.

  • http://www.cebelca.biz/ JM

    Why don’t you just install your own and be a “master of your own domain” :) …. I love VPS-s so I can install and use weird stuff, unlike the old shared hosting solutions.

  • http://swizec.com Swizec

    Because the person I’m doing this for is deploying to Heroku :P

    And Heroku is seriously awesome. They make life much much easier than having to deal with icky sysadmin stuff.

  • http://swizec.com Swizec

    Awesome! Thanks for that :)

    By the way, how come your driver doesn’t support the mongo:// schema? Is there any specific reason?

  • Pingback: Node.Js: Links, News And Resources (6) « Angel “Java” Lopez on Blog