Deserialized The Ramblings of a Web Architect

23Feb/107

The Current State of MongoDB and C#

Posted by Bryan Migliorisi

As a C# developer, I am often disappointed with the lack of drivers and connectors to cool services like MongoDB.  All the cool languages (and Java) get all the love but C# is often an afterthought.

Luckily for me, there are some kickass developers in the C# community who also share my frustration and as such, they have begun building their own C# MongoDB drivers.

I keep stumbling across more and more C# related MongoDB projects, so I figured I would write up a list and some short descriptions of these projects.

List of C# MongoDB Projects

Each of these projects are still rather new, so expect some features to be missing or not fully functional.  A couple of them are usable in your projects today while the rest are still under heavy development

mongodb-csharp

Originally written by Sam Corder (@SamCorder) with help from a handful of contributers, this is the most complete driver of the bunch. It has been evolving quickly and Sam & team are very quick to resolve any bugs that may arise.

I am using this driver in 2 projects that I am working on and so far things have been great.  It even includes GridFS suport.

From the project description:

Current Features

  • Connect to a server.
  • Query
  • Insert
  • Update
  • Delete
  • All BSON types supported
  • DBRef support
  • Isolation and conversion between BSON types and native .net types.
  • Database, Collection and Cursor objects.
  • Index handling routines (List, Create, Drop)
  • Count
  • Roughly 80% unit test coverage. This can and will be improved on.
  • Paired connections
  • Authentication (Does not reauthorize on auto reconnect yet).
  • Database Commands
  • Basic Linq support
  • GridFS support
  • Map Reduce helpers.
  • hint, explain, $where

They are currently working on connection management features (auto reconnect, connection pooling, etc).

Get involved or check out the code at their mongodb-csharp project page on Github.

mongodb-net

Written by the unnamed developer at DevFuel.com, the mongo-net project aims to be a C# port of the 10Gen\MongoDB official Java driver.  While a lot of work has been done and a load of code written, it is currently unusable.  Over the past couple of weeks a significant amount of progress has been made and functionality is beginning to work but it seems that a functional state is months away.

I would keep an eye on this project, though, as having an API compatible with the official Java driver has its benefits.

Get involved or check out the code at their mongodb-net project page on Google Code.

MongoDB.Emitter

Andrew Rondeau’s MongoDB.Emitter is a pretty cool project that provides a strongly-typed Document mapper for C#.  It works in conjunction with Sam Corder’s mongodb-csharp driver allowing the programmer to define strongly typed interfaces and properties.

I have not tried this yet, but this will be on my list of things to check out.

Get involved or check out the code at their MongoDB.Emitter project page on bitbucket.

CSMongo

Hugo Bonacci (@hugoware) has been working on a driver of his own called CSMongo. CSMongo doesnt support everything that mongodb-csharp does but it does have some interesting features, such as the approach to creating Mongo Documents.  Their approach definitely has a more dynamic feel to it which fites nicely in the unstructured MongoDB world.

I am looking forward to the next version which should have more features including support for Hugo’s own jLinq.

Code doesn't appear to be released yet but you can follow his progress at his blog, Hugoware.

simple-mongodb

Simple-mongdb is another project without public source that is being worked on by Daniel Wertheim (@danielwertheim).  I am not sure if it is even being actively developed but it too has some nice ideas.  The goal of this project is to keep the driver JSON-centric and should be compatible with awesome Newtonsoft’s JSON.net library.

They have a few examples of the proposed API but no code has been released to make said examples work.  This is another one to keep an eye on in the meantime.

Check out the simple-mongodb project page on Google Code.

DocumentConverter

This is a small class I wrote that works with mongodb-csharp.  Its name will likely change at some point if and when it gets packaged up and put on source control.  It exposes two functions that will allow any C# class to convert to and from a MongoDB Document object automatically.  It makes my life a lot easier and it uses System.Reflection to do this.

Read more about DocumentConverter on this blog post.

Conclusion

Well it looks like there is a significant amount of interest in MongoDB from the C# community which is great news because it looks like MongoDB is going to continue to thrive and grow.  My bet is that Sam Corder’s driver will be the most common C# driver, simply because it is so far ahead of the rest but time will tell.  Extensions of Sam’s project, such as MongoDB.Emitter, are equally as cool as the drivers they are built on.

Thanks toeveryone who has contributed to these drivers.  Each of them have some great concepts and I hope that one day we will have a driver that supports all these great ideas and features.

If there are any more projects that I have missed – let me know in the comments!