Update: Mongo-GLib

Mongo-GLib was an attempt I did to write a MongoDB driver for GObject. I actually use it quite a bit at work now. Especially the MongoBson and MongoBsonStream structures for reading MongoDB backups off disk. It turns out to be quite useful for analyzing your backups as they stream to disk.

However, last night I added a new hack to the code-base as I work on cleaning up the API and making it more usuable. You can now implement your own MongoDB server. This could be useful if you want to, or need to, store data in a system other than MongoDB but want to export the data in MongoDB format. It allows you to piggyback on top of the client-side failover of the MongoDB drivers as well. It's almost always better to use a tested failover design than make your own. Also, I hope to use this to implement more comprehensive unit tests, checking both sides of the wire protocol.

My goal for using this is to be able to store certain pieces of data in Redis (as it had data-structures optimized for my use case) but would like to provide failover and documents using MongoDB.

It is just starting to work, so there is plenty more to do, but I thought it was worthy of a blog update.

from gi.repository import Mongo
from gi.repository import GLib

def handleRequest(server, client, message):
    bson = Mongo.Bson()
    bson.append_string("hello", "world")
    message.set_reply_bson(Mongo.ReplyFlags.NONE, bson)
    return True

Server = Mongo.Server()
Server.add_inet_port(27017, None)
Server.connect('request-query', handleRequest)

GLib.MainLoop().run()

It works from JavaScript as well.

https://github.com/chergert/mongo-glib

-- Christian Hergert 2012-10-31

Back to Index