Monday, April 11, 2011

MongoHQ and Node

THIS IS OUT OF DATE CHECK OUT THIS NEW ARTICLE INSTEAD

MongoHQ

Free MongoDB hosting for playing around with Mongo. Free for 16mb of storage. $5/month for 256mb. It's good for small stuff and getting started with Mongo.

Difficulties

One of the problems I found while connecting to MongoHQ from node was the authentication. Most of the MongoDB libraries for node are very simple to use, but cut some of the features from the mongodb native library like authentication (or at least make it difficult to access), so I ended up rolling my own wrapper to make the authentication step as easy as possible.

Custom Wrapper

I wrote a simple wrapper to the Node MongoDB native driver that made it easier to hook into MongoHQ, which requires authentication. It may be useful to other people as well:


Connecting the pieces

To get this custom driver up an running it's very simple.
  • Initialize it.
  • Register your collections.
  • User it

Docs and Help

6 comments:

  1. This is very nice - I'm using it for DotCloud (originally found it when I was playing with MongoHQ).

    I'm able to read from a collection but am having trouble inserting into it.

    This find statement works fine:
    db.stuff.find(function(err, cursor) {
    cursor.toArray(function(err, stuff) {
    res.render('success', {
    stuff: JSON.stringify(stuff)
    });
    });
    });

    I've tried the node-mongodb-native, mongodb CLI and some (what I considered) clever methods for inserting, all to no avail. Maybe it's syntax but I think I'm missing something. How are you inserting/updating with this wrapper?

    ReplyDelete
  2. Hey Kyle,

    Sorry to not be getting back to you.

    Try something like this:
    var stuff = {awesome:true}
    db.stuff.insert(stuff)

    by default there's not really a callback

    You might want to use the mongoskin wrapper, which is very similar to the mongo shell:
    https://github.com/guileen/node-mongoskin/#inherit-inserting

    Feel free to e-mail me with a more specific question!

    ReplyDelete
  3. How's the performance/latency of MongoHQ? I was planning to put some perf analysis to my list of MongoDb hosting there.
    Any input will be helpful. Thanks.

    ReplyDelete
  4. Hey. I don't have any real stats. I can probably get some. I will say this though. My page is on a free no.de box with like 384mb of ram and the page loads SUPER FAST with no cacheing. (See for yourself, http://www.wereviewutah.com/) MongoHQ def works really well for small stuff.

    At i.TV, we have a big production box running on the Rackspace cloud with 16bg of ram and of course it's insanely fast when we hit it from our app servers on the same network.

    ReplyDelete
  5. Oh, great. I will check them up again (for latency between servers etc) Thanks again.

    ReplyDelete
  6. At i.TV, we have a big production box running on the Rackspace cloud with 16bg of ram and of course it's insanely fast when we hit it from our app servers on the same network. velvet bed sheets price in pakistan , deep mattress protector ,

    ReplyDelete