Andrew Theken's C# Blog

A public place for internal thoughts.

No SQL, No Problems (or: Mo’ SQL, Mo’ Problems)

Posted by Andrew Theken on February 26, 2010

Let’s talk about NoSQL:

If you’ve been following the latest trends in the .net world via reddit, twitter, or your favorite blogs, you’ve been seeing a great deal of chatter about a term called NoSQL. Some might even call it a ‘movement’ but that scares me just a little bit – when things become ‘movements’, their meanings become a bit nebulous. Here are a few cases where a ‘NoSQL’ solution might be useful to you:

  • You have a several multi-million row tables that each have foreign key relationships to one another, joins against these tables pound the server, but must return rapidly.
  • You have “jagged” datasets where each record has a different composition of fields and children, those children in turn have their own properties.
  • You need to find a root record based on a complex set of relations to other tables.

A New Hope:

There are many NoSQL options out there right now, but for reasons that will become obvious very shortly, I am going to talk about one in particular: MongoDB. MongoDB is a “document-oriented” database written in c++ that stores your documents in a format called “BSON.” BSON is conceptually similar to JSON, but is a binary format that also explicitly carries type information.

Mongo has some nice features, including:

  • Dynamic creation and allocation of databases and document collections (including the capability of having nested collections)
  • Ability to do deep-graph searches (i.e. locate documents based on child properties of the document)
  • Ability to execute arbitrary JavaScript functions for aggregation and as criteria of searching
  • Very few requirements on what can be inserted into a database
  • Support for regex searching.
  • Speed
  • …more…

But you should be warned: MongoDB doesn’t make ACID guarantees. If you’re storing twitter updates, you’re probably ok, if you’re storing financial transactions, don’t use MongoDB.

But this is a blog about C# where we have strong & static typing, we live and breath order in our daily lives (ha!). “Leave all that ‘No SQL’ to those dirty Ruby hippies”, you say.

Let me break it to you: NoSQL doesn’t mean NoStructure.

To that end, I’ve been (with lots of help) incubating a project on GitHub called NoRM. In brief, NoRM is a library to connect to MongoDB using .Net (and Mono) and to query and hydrate documents into strongly & statically-typed documents in a way that doesn’t make us C# developers queasy.

We still have a long way to go before a 1.0 release, but I think it’s important to point out some of the guys that have been most enthusiastic about this project (and contributed some great code and ideas) include:

James Avery
Jason Alexander
Rob Conery
Nate Kohari
Karl Seguin

These guys really know their stuff, and I am so happy to have them working on this with me. My next post will be about some of the design decisions we’ve made with NoRM and how you might use it (soon) in some of your own projects.


5 Responses to “No SQL, No Problems (or: Mo’ SQL, Mo’ Problems)”

  1. brennydoogles said

    What kind of syntax is used to interact with the NoSQL Databases?

    • I cannot speak for all of the NoSQL options. Querying scenarios vary, but in MongoDB, this the general form of interaction:

      var db = use <aDBName>
      db.find({aPropertyOfTheDocument:_valueToSearchFor_})

      There are much more sophisticated interactions that can be achieved, but the above is the basic query form.

      In NoRM, the experience is very similar to LINQ-to-SQL, the critical difference is that we don’t really need to do anything to define the schema in MongoDB before we use it, we simply define our classes (document templates) in C# and use them.

      • brennydoogles said

        Very cool, I look forward to checking it out when it is ready!

  2. You beat me to it. I’ve been waiting (and wanting to build) a good LINQ > Mongo interface. My team has built a decent one for Java.

    Thank you for contributing this to the community — its some of the best open-source code I’ve seen in a long time!

  3. [...] a comment » As promised in my previous post, I am going to introduce you to a project that I’ve been working on with a great team of [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>