Damien Caselli, one of the first brave souls to use Mongo Explorer, reported an issue with time travelling in Mongo Explorer. Luckily, it wasn’t anything serious: just a misunderstanding between me, Cocoa and JavaScript.

To celebrate the No Time Travelling Issues, I’ve released version 1.0.2 of Mongo Explorer. Get yours: mongo-explorer-v1.0.2.zip

Yes, I’m aware of Sparkle, and yes, it will eventually make it into Mongo Explorer. That, and a million other little things.

In the past few months, I was looking for an excuse to write a native Mac Cocoa application. We use MongoDB at Bloom Digital to handle our analytics needs. I had tried mongohub, but my itch wasn’t scratched: I wanted something that displayed my data in tables, not as some kind of outline. Thus was born Mongo Explorer.

Mongo Explorer v1.0.0, detailing how to view a single collection's documents and a single document opened in flat view.
Click to enlarge

If you tell me “Why didn’t you fork mongohub and add your code”, I’ll tell you I was intimidated by a larger Cocoa application. I wanted something simple from which I could learn everything I wanted: from the grounds up. Of course, once I’m “done” (for some measure of done-ness), the code base will be much larger.

One useful piece of code that might be useful for others is a Mongo Driver for Objective-C. Underlying Mongo Explorer is an abstraction for Mongo connections that’s similar to the Ruby driver. It’s not yet a framework, since I don’t yet know how to do that, but hey, this is a learning exercise for me. One nice thing about this abstraction is that it’s built directly atop the official Mongo C driver: thus it inherits it’s abilities, but some of it’s quirks as well.

What can you expect from Mongo Explorer today? You can open a connection to any local MongoDB instance (manually open an SSH tunnel if you want a remote instance), browse the server’s databases and collections, and list your collection’s documents. For each document, you’ll get what I call the flat view. The flat view is a dot-separated list of keys, followed by the value. It’s useful to view nested objects:


1 obj = {"rp" => {"a" => 1, "b" => {"c" => "d"}}}
2 # Flat view
3 # rp.a => 1
4 # rp.b.c => d

The flat view was my biggest impetus to write Mongo Explorer.

What’s broken? First, this needs some kind of icon. Also, don’t expect to browse multi-million document collections just yet. Cocoa wants to fully materialize the NSTableView rows, and I don’t know how to handle that yet. I do have an MEArray class that helps somewhat, but it’s not perfect yet. Learning exercise, remember? I’ve successfully viewed collections with slightly less than 20,000 document with no issues.

If you’re interested in following, you can play around on GitHub, or even download the first official release: Mongo Explorer, v1.0.1

UPDATE: Pushed 1.0.1, as 1.0.0 didn’t include it’s frameworks, and was 10.6 only.

I’m writing a Cocoa application to browse and administer a Mongo DB. This is a fun side-project. I’m using the Mongo driver from Objective-C, hence there might be differences for you.

First off, we need to connect to Mongo, and to do that, we need to tell Mongo about the connection information, namely the host and port:


1 mongo_connection_options opts;
2 strcpy(opts.host,
3 [[self.connectionInfo objectForKey:MEHost] cString]);
4 opts.port = [[self.connectionInfo objectForKey:MEPort] intValue];
5 /* mongo doesn’t have a default port constant or define */
6 if (0 == opts.port) opts.port = 27017;

connectionInfo above is an instance of NSDictionary. The available keys are declared in NewConnectionController.

After we’ve prepared the connection options, it’s time to connect:


1 connection = (mongo_connection *)malloc(sizeof(mongo_connection));
2 if (!connection) return;
3
4 mongo_conn_return result = mongo_connect(connection, &opts);
5 if (mongo_conn_success == result) return;

connection above was declared as a pointer to a mongo_connection structure in DatabaseController. If the connection succeeds, I simply continue. If the connection fails, I fall-through and inform the user using an NSAlert, shown as a sheet.

I haven’t yet needed to authenticate to Mongo, but it seems simple to call mongo_cmd_authenticate().

Don’t forget the tests available in the mongo driver itself.

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on