<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Deserialized &#187; mongodb</title>
	<atom:link href="http://deserialized.com/tag/mongodb/feed/" rel="self" type="application/rss+xml" />
	<link>http://deserialized.com</link>
	<description>The Ramblings of a Web Architect</description>
	<lastBuildDate>Mon, 23 Jan 2012 16:33:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Why I choose the Microsoft stack for my new startup</title>
		<link>http://deserialized.com/startups/why-i-choose-the-microsoft-stack-for-my-new-startup/</link>
		<comments>http://deserialized.com/startups/why-i-choose-the-microsoft-stack-for-my-new-startup/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 15:39:36 +0000</pubDate>
		<dc:creator>Bryan Migliorisi</dc:creator>
				<category><![CDATA[startups]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://deserialized.com/c-sharp/why-i-choose-the-microsoft-stack-for-my-new-startup/</guid>
		<description><![CDATA[One thing is for sure - Microsoft gets a bad rep these days.  Maybe its because of Windows Vista.  Maybe its because of classic ASP, or even ASP.NET’s WebForms.  Maybe it is because they are a large company who’s focus has too long been on the enterprise, and not enough on the consumer.  Most likely, [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeserialized.com%2Fstartups%2Fwhy-i-choose-the-microsoft-stack-for-my-new-startup%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeserialized.com%2Fstartups%2Fwhy-i-choose-the-microsoft-stack-for-my-new-startup%2F&amp;source=Deserialized&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://deserialized.com/wp-content/uploads/2011/04/Microsoft-web.jpg"><img style="background-image: none; margin: 0px 14px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: left; padding-top: 0px; border: 0px;" title="Microsoft web" src="http://deserialized.com/wp-content/uploads/2011/04/Microsoft-web_thumb.jpg" border="0" alt="Microsoft web" width="244" height="194" align="left" /></a>One thing is for sure - Microsoft gets a bad rep these days.  Maybe its because of Windows Vista.  Maybe its because of classic ASP, or even ASP.NET’s WebForms.  Maybe it is because they are a large company who’s focus has too long been on the enterprise, and not enough on the consumer.  Most likely, though, it is because its simply cool to make fun of Microsoft.</p>
<p>I had plenty of options when I decided to start building a new web application.  My favorite language is C#.  I’m not talking about web app frameworks, or frameworks in general – no, just the language.  I love that C# does not do very much magic, like Ruby does.  I love that C# has a cleaner and more expressive syntax than Java does.  I won’t even compare the language syntax and API to that of PHP. Of course, there were other options too, such as Python and Scala.</p>
<h2>Java</h2>
<p>I’ve been working for the past 3 years with Java and Spring 2.x.  Older versions of Spring are god-awful, what with their dependence on a metric ton of XML configuration files.  Spring 2.5 began to add support for annotations (attributes in C#) and Spring 3 continued to improve even further in this area.  Java has a fairly good amount of cool technologies, frameworks, and specifications too.  For me, though, the ecosystem feels very broken.  Having many options is good.  Having <em>too many </em>options is bad.</p>
<h2>Ruby and RoR</h2>
<p>I began toying around with Ruby and, consequently, Ruby on Rails too.  It is a nice and powerful language and framework but at the end of the day it didn’t feel right.  I like type safety and compile-time checks.  I like knowing what my code does – in fact, I like telling my code what to do!  Ruby loves to do magic for you.  Rails builds on top of this magic to provide even more magic.  Honestly, it is pretty impressive but for me, it just didn’t feel right.  I’ve spoken to fellow developers who feel the same way: It is very cool, but doesn’t feel natural.</p>
<p>With that said, I have already written a couple of supporting services in Ruby for my new app.. because Ruby was the better choice for those services.  They are exposed as web services running on Sinatra.</p>
<h2>PHP</h2>
<p>I’ve used several PHP frameworks, including <a href="http://cakephp.org/">CakePHP</a>, <a href="http://codeigniter.com/">CodeIgniter</a>, <a href="http://kohanaframework.org/">Kohana</a>, <a href="http://lithify.me/">Lithium</a> and <a href="http://www.yiiframework.com/">Yii</a>.  My favorites are the last two, Lithium and Yii.  They both do a great job of making it easy to build web applications and both are extensible.  However, I despise PHP as a language.  It is arguably one of the ugliest languages ever “designed.”  (It really never was designed, it just grew organically which is why function names, parameter order, etc is so different from function to function)  If I choose PHP, I know I would not be able to sleep at night.</p>
<p>As for the others, I just didn’t have enough experience with them to make a fair (to me) comparison.  Nor did I have several months to learn them to a point that would make a fair comparison.</p>
<h2>Home, sweet, home</h2>
<p>This all brings me back to my personal favorite language, C#.  It has a very clean and expressive API (look at LINQ).  The ecosystem is smaller than that of Java, but it is tighter because one company runs the show – Microsoft.  With Microsoft’s latest MVC framework release, ASP.NET MVC3, writing a web application has become so simple its scary.</p>
<p>The ill-named ASP.NET MVC framework learned quite a bit from Rails and the open source community in general. Microsoft studied what people want to do with their frameworks and what they don’t – and it shows.  ASP.NET MVC is a fantastic framework and they’ve built in extensibility at every level.  Don’t like something? Write your own and plug it in.  It really is that easy. Seriously.</p>
<p>With version 3 comes the Razor view engine which I think is absolutely beautiful.  I’ve used several view engines in different languages but Razor stands out to me as a new approach (which is sometimes scary to some people) where you don’t need weird braces, brackets, or custom HTML tags to render content or run code in your views.  I think its just very streamlined and easy to look at and read.</p>
<h2>It scales – they all do!</h2>
<p>Scalability isn't a feature of any language or framework.  Nowhere is there a bullet that lists scalability as an important feature.  Instead, scalability is something the application designers must think about while they built there app, no matter which language its built in.</p>
<p>ASP.NET scales very well.  So do Java, Ruby, PHP and all the others – when done right.  Scalability is about engineers, not language.</p>
<h2>The Community</h2>
<p>People often complain that Microsoft is a large corporation who doesn’t care about the community. Those same people often ignore the fact that Microsoft has <a href="http://referencesource.microsoft.com/netframework.aspx">open sourced much of the .NET framework</a>, including <a href="http://aspnet.codeplex.com/">ASP.NET MVC</a>. They ignore that most (though, not all) .NET programs will run happily on any operating system, including Linux, OSX, and iOS. This is made possible through the open source <a href="http://www.mono-project.com/">Mono project</a>, sponsored by Microsoft and Novell.</p>
<p>Microsoft and the community also collaborated on a cool new package manager called <a href="http://nuget.org/">Nuget</a>.  It is similar in nature to Ruby’s Gems and Java’s Maven, though it is not a copy of either of them.  What is amazing is that immediately upon its release, cool open source (and some commercial) libraries began showing up in the <a href="http://nuget.org/">Nuget</a> listing.  So many libraries that I, and presumably many other people, had never heard of were suddenly at our fingertips, ready to be installed as easily as a Ruby  gem.</p>
<p>Since releasing <a href="http://nuget.org/">Nuget</a>, the amount of packages has been steadily <a href="http://stats.nuget.org/">growing</a> and the amount of package downloads has been growing even faster.</p>
<p>In addition to this,  there is a healthy community of people willing to help you solve any issues you have.  You can head over the the <a href="http://forums.asp.net/">ASP.NET Forums</a> or <a href="http://stackoverflow.com/">StackOverflow</a> if you need help with anything and your question will be answered usually in minutes.</p>
<h2>The Microsoft stack, minus Microsoft</h2>
<p>For my newest web application, I’ve made the decision to go with <a href="http://www.mongodb.org/">MongoDB</a> for my database.  It is a super fast, document-oriented database as opposed to standard relational databases such as MySql, Postgres, and Microsoft’s own SQLServer.  I made this decision because it best fits the type of data I will be storing and I’ve been working with <a href="http://www.mongodb.org/">MongoDB</a> since its alpha stage so I know what it is capable of.</p>
<p>MongoDB runs on Windows but runs better on Linux, and that is where I plan to run it.</p>
<p>If C# code and ASP.NET MVC applications can also run on Linux, then you have no need to run on Windows.  You have removed Microsoft from the Microsoft stack.  Where is your vendor lock in now?</p>
<p>I will most likely run my application on Windows Server 2008 but the point is that I don’t have to if I don’t want to.  Even with the Microsoft stack, I still have my options.</p>
<h2>Bonus: WebSite Spark and BizSpark</h2>
<p><a href="http://www.microsoft.com/web/websitespark/">WebSite Spark</a> and <a href="http://www.microsoft.com/bizspark/">BizSpark</a> are two initiatives by Microsoft to bring down the initial cost of getting up and running with the Microsoft platform so that you can get all the tools and resources you need to do it right.</p>
<h2>Conclusion</h2>
<p>With Microsoft's new commitment to building better tools for the web and working with the community, I feel that my decision to go with the Microsoft stack is the right one, for me.  You may not agree – and that is fine – but don’t knock it before you try it.  Version 3 of ASP.NET MVC brings some really great stuff to the table. Nuget makes finding packages just as easy as it has been for Ruby developers for years. Portability of the code means not needing to worry about vendor lock-in.</p>
<p>So far, I am more than happy with my decision.</p>
]]></content:encoded>
			<wfw:commentRss>http://deserialized.com/startups/why-i-choose-the-microsoft-stack-for-my-new-startup/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>ObjectID’s with MongoDB and the mongodb-csharp driver</title>
		<link>http://deserialized.com/c-sharp/objectids-with-mongodb-and-the-mongodb-csharp-driver/</link>
		<comments>http://deserialized.com/c-sharp/objectids-with-mongodb-and-the-mongodb-csharp-driver/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 17:06:38 +0000</pubDate>
		<dc:creator>Bryan Migliorisi</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Gotcha]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://deserialized.com/objectids-with-mongodb-and-the-mongodb-csharp-driver/</guid>
		<description><![CDATA[I mist say, the latest release of mongodb-csharp is rather awesome.  Typed collections and LINQ support mean I can worry more about my application than about the data layer. Here is an example of using typed collections: public class Customer { public Oid Id { get; set; } public string Name { get; set; } [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeserialized.com%2Fc-sharp%2Fobjectids-with-mongodb-and-the-mongodb-csharp-driver%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeserialized.com%2Fc-sharp%2Fobjectids-with-mongodb-and-the-mongodb-csharp-driver%2F&amp;source=Deserialized&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I mist say, the latest release of <a title="MongoDB C# Driver" href="http://github.com/samus/mongodb-csharp">mongodb-csharp</a> is rather awesome.  Typed collections and LINQ support mean I can worry more about my application than about the data layer.</p>
<p>Here is an example of using typed collections:</p>
<pre class="brush: csharp">public class Customer
{
	public Oid Id { get; set; }
	public string Name { get; set; }
	public CustomerBillingInfo Billing { get; set; }
	public List Depts { get; set; }
}

public void AddCustomer(Customer customer) {
	...(code removed for simplicity)...
	IMongoCollection collection = database.GetCollection();
	collection.Save(customer);
}</pre>
<h2>Gotcha: Beware of the ID property!</h2>
<p>One thing that threw me off when I began using the typed collections was that I had defined my ID property as “<span style="font-family: 'Courier New';">_id</span>” because That is what <a title="MongoDB" href="http://www.mongodb.org/">MongoDB</a> uses internally.  While this made sense to me, the <span style="font-family: 'Courier New';">mongod</span> process kept throwing errors whenever I tried the following:</p>
<pre class="brush: csharp">...(code removed for simplicity)...
IMongoCollection&lt;customer&gt; collection = database.GetCollection&lt;customer&gt;();
Customer customer = collection.Linq().First(c =&gt; c.Name == "test customer");
customer.Name = "A new name!";
collection.Save(customer);</pre>
<p>The error looked something like this:</p>
<pre class="brush: csharp">Fri Jun 25 10:43:14 Exception 11000:E11000 duplicate key error index: test06.Customer.$_id_  dup key: { : ObjId(4c24c07a189cf31bd4000002) }
Fri Jun 25 10:43:14    Caught Assertion in insert , continuing
Fri Jun 25 10:43:14 insert test06.Customer exception userassert:E11000 duplicate key error index: test06.Customer.$_id_  dup key: { : ObjId(4c24c07a189cf31bd4000002) } 21ms</pre>
<p>It was driving me crazy for days before I realized that the driver was doing some magic – the POCO object needed its ID to be named “Id” instead of “_id” an as soon as I changed that – it started working properly.</p>
]]></content:encoded>
			<wfw:commentRss>http://deserialized.com/c-sharp/objectids-with-mongodb-and-the-mongodb-csharp-driver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Convert C# classes to and from MongoDB Documents automatically using .NET reflection</title>
		<link>http://deserialized.com/c-sharp/convert-csharp-classes-to-and-from-mongodb-documents-automatically-using-net-reflection/</link>
		<comments>http://deserialized.com/c-sharp/convert-csharp-classes-to-and-from-mongodb-documents-automatically-using-net-reflection/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 15:47:23 +0000</pubDate>
		<dc:creator>Bryan Migliorisi</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[mongo]]></category>

		<guid isPermaLink="false">http://deserialized.com/?p=53</guid>
		<description><![CDATA[There are a number of C# based MongoDB projects being actively developed right now but one thing that I needed was a way to convert a standard C# class to a MongoDB document for easy insertion.&#160; It isn't hard to manually type out and set each property by hand, but it certainly is not the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeserialized.com%2Fc-sharp%2Fconvert-csharp-classes-to-and-from-mongodb-documents-automatically-using-net-reflection%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeserialized.com%2Fc-sharp%2Fconvert-csharp-classes-to-and-from-mongodb-documents-automatically-using-net-reflection%2F&amp;source=Deserialized&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>There are a <a href="http://deserialized.com/the-state-of-mongodb-and-csharp/">number of C# based MongoDB projects</a> being actively developed right now but one thing that I needed was a way to convert a standard C# class to a <a href="http://www.mongodb.com">MongoDB</a> document for easy insertion.&#160; It isn't hard to manually type out and set each property by hand, but it certainly is not the most efficient way, especially when you know you are going to be doing it a lot.</p>
<p>&#160;</p>
<p>For example:</p>
<p>Lets say I have a class called <em>SomeClass</em> that looks something like this:</p>
<pre class="brush: csharp">class SomeClass {
	public string StringTest;
	public int IntTest;
}</pre>
<p>And somewhere in my code, I have an instance of this class named <em>someClassInstance</em>.&#160; If I want to create a MongoDB document from this class, I’d have to do something like this:</p>
<pre class="brush: csharp">Document document = new Document();
document.add('StringTest', someClassInstance.StringTest);
document.add('IntTest', someClassInstance.IntTest);</pre>
<p>So that isn't such a big deal, right? But what about when I have a class with many more properties?&#160; Then it starts to get messy and cumbersome.&#160; I thought that there should be an straightforward way to easily convert any class to a mongo-csharp compatible Document object. (I am using <a href="http://twitter.com/samcorder">Sam Corder’s</a> <a href="http://github.com/samus/mongodb-csharp">mongo-csharp driver</a>, so that I am targeting the Document object from that library.)</p>
<h3>Default values</h3>
<p>I also wanted to have a way to specify what the default values were for each class property so that when we did the conversion, we would (hopefully) not end up with any null values.&#160; Plus, if for some reason there was a document in MongoDB that was missing a particular key-value pair, the DocumentConverter would automatically fill in that empty field with the default value so in the code we should never have any nulls.</p>
<p>This is something that I would like for my own purposes and may not suit everyone’s needs.&#160; If it doesn't, simply leave off the DefaultValueAttribute and you’ll never know the difference.</p>
<h3>My proposed solution</h3>
<p>I figured the easiest way to accomplish this was to create a class that would encapsulate all the functionality needed to convert to and from Document objects and have my other classes inherit from that one. I imagined that the above code would change to something like this:</p>
<pre class="brush: csharp">class SomeClass : DocumentConverter {
	[Attributes.DefaultValue(&quot;Default StringTest value!&quot;)]
	public string StringTest;
	[Attributes.DefaultValue(16)]
	public int IntTest;
}</pre>
<p>And to do the conversion would be very simple.&#160; To convert from <em>someClass</em> to <em>Document</em> would be:</p>
<pre class="brush: csharp">Document document = someClassInstance.ToMongoDocument();</pre>
<p>To convert from a <em>Document</em> object to <em>someClass</em> would be:</p>
<pre class="brush: csharp">SomeClass someOtherClassInstance = new SomeClass();
omeOtherClassInstance .FromMongoDocument(someDocumentObject);</pre>
<h3>The DefaultAttribute class</h3>
<pre class="brush: csharp">using System;
namespace MyApp.Attributes
{
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
    class DefaultValueAttribute : Attribute
    {
        private readonly object _value;

        public DefaultValueAttribute(object Value)
        {
            _value = Value;
        }

        public object GetDefaultValue()
        {
            return _value;
        }
    }
}</pre>
<h3>The DocumentConverter class</h3>
<p>Reflection isn't something that I use too often so there may be better ways of accomplishing what I am trying to do, but this is what I’ve got for now.&#160; If there are better ways, please let me know.&#160; Without further ado…</p>
<pre class="brush: csharp">using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using MyApp.Classes.Attributes;
using MongoDB.Driver;

namespace MyApp.Classes
{
    public class DocumentConverter
    {
        public void FromMongoDocument(Document document)
        {
            foreach (DictionaryEntry kvp in document)
            {
                object propertyValue;
                if (kvp.Value != null &amp;&amp; (kvp.Value.GetType() == typeof(Document)))
                {
                    // We have a document object - Now lets get a reference to the class property's type
                    var propertyType = GetType().GetProperty(kvp.Key.ToString()).PropertyType;

                    // create new instance of that class
                    var propertyInstance = Activator.CreateInstance(propertyType);

                    // call FromMongoDocument on that class and pass in the document
                    MethodInfo method = propertyInstance.GetType().GetMethod(&quot;FromMongoDocument&quot;);
                    method.Invoke(propertyInstance, new[] { kvp.Value });

                    propertyValue = propertyInstance;
                }
                else
                {
                    // This is not a Document so lets just assign the value
                    propertyValue = kvp.Value;
                }

                GetType().GetProperty(kvp.Key.ToString()).SetValue(this, propertyValue, null);
            }

        }

        public Document ToMongoDocument()
        {
            Document document = new Document();

            foreach (PropertyInfo property in GetType().GetProperties())
            {
                // Get the value of this property
                object propertyValue = property.GetValue(this, null);

                // If this value is null, then lets try to see if there is a default value attribute and assign that
                if (propertyValue == null)
                {
                    object[] attributes = property.GetCustomAttributes(typeof(DefaultValueAttribute), true);
                    foreach (DefaultValueAttribute defaultValue in attributes.Cast<defaultvalueattribute>())
                    {
                        propertyValue = defaultValue.GetDefaultValue();
                    }
                    document.Add(property.Name, propertyValue);
                }
                else
                {
                    // We have a property, now lets see if this property has a ToMongoDocument method
                    MethodInfo method = propertyValue.GetType().GetMethod(&quot;ToMongoDocument&quot;);

                    if (method == null)
                    {
                        document.Add(property.Name, property.GetValue(this, null));
                    }
                    else
                    {
                        document.Add(property.Name, method.Invoke(propertyValue, null));
                    }
                }
            }
            return document;
        }
    }
}</pre>
<h3>That’s all for now</h3>
<p>I hope this is useful for someone.&#160; It is a rough draft of what I threw together last night at around 1AM while half asleep.&#160; So far, it has passed all of my initial tests but if you have suggestions to make it better, please leave some comments here. </p>
]]></content:encoded>
			<wfw:commentRss>http://deserialized.com/c-sharp/convert-csharp-classes-to-and-from-mongodb-documents-automatically-using-net-reflection/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The Current State of MongoDB and C#</title>
		<link>http://deserialized.com/c-sharp/the-state-of-mongodb-and-csharp/</link>
		<comments>http://deserialized.com/c-sharp/the-state-of-mongodb-and-csharp/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 19:24:03 +0000</pubDate>
		<dc:creator>Bryan Migliorisi</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[mongo]]></category>
		<category><![CDATA[nosql]]></category>

		<guid isPermaLink="false">http://deserialized.com/the-state-of-mondodb-and-csharp/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fdeserialized.com%2Fc-sharp%2Fthe-state-of-mongodb-and-csharp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fdeserialized.com%2Fc-sharp%2Fthe-state-of-mongodb-and-csharp%2F&amp;source=Deserialized&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>As a C# developer, I am often disappointed with the lack of drivers and connectors to cool services like <a href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a>.  All the cool languages (and Java) get all the love but C# is often an afterthought.</p>
<p>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# <a href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a> drivers.</p>
<p>I keep stumbling across more and more C# related <a href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a> projects, so I figured I would write up a list and some short descriptions of these projects.</p>
<p><strong> </strong></p>
<h2>List of C# <a href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a> Projects</h2>
<p>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</p>
<h3><strong><a href="http://github.com/samus/mongodb-csharp">mongodb-csharp</a></strong></h3>
<p>Originally written by Sam Corder (<a href="http://twitter.com/samcorder">@SamCorder</a>) with help from a handful of contributers, this is the most complete driver of the bunch. It has been evolving quickly and Sam &amp; team are very quick to resolve any bugs that may arise.</p>
<p>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.</p>
<p>From the project description:</p>
<h4>Current Features</h4>
<ul>
<li>Connect to a server.</li>
<li>Query</li>
<li>Insert</li>
<li>Update</li>
<li>Delete</li>
<li>All BSON types supported</li>
<li>DBRef support</li>
<li>Isolation and conversion between BSON types and native .net types.</li>
<li>Database, Collection and Cursor objects.</li>
<li>Index handling routines (List, Create, Drop)</li>
<li>Count</li>
<li>Roughly 80% unit test coverage. This can and will be improved on.</li>
<li>Paired connections</li>
<li>Authentication (Does not reauthorize on auto reconnect yet).</li>
<li>Database Commands</li>
<li>Basic Linq support</li>
<li>GridFS support</li>
<li>Map Reduce helpers.</li>
<li>hint, explain, $where</li>
</ul>
<p>They are currently working on connection management features (auto reconnect, connection pooling, etc).</p>
<p>Get involved or check out the code at their <a href="http://github.com/samus/mongodb-csharp">mongodb-csharp project page on Github</a>.</p>
<h3></h3>
<h3>mongodb-net</h3>
<p>Written by the unnamed developer at <a href="http://www.devfuel.com/">DevFuel.com</a>, 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.</p>
<p>I would keep an eye on this project, though, as having an API compatible with the official Java driver has its benefits.</p>
<p>Get involved or check out the code at their <a href="http://code.google.com/p/mongodb-net/">mongodb-net project page on Google Code</a>.</p>
<p><strong> </strong></p>
<h3>MongoDB.Emitter</h3>
<p>Andrew Rondeau’s <a href="http://groups.google.com/group/mongodb-user/browse_thread/thread/d85b91a68145bee3">MongoDB.Emitter</a> 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.</p>
<p>I have not tried this yet, but this will be on my list of things to check out.</p>
<p>Get involved or check out the code at their <a href="http://bitbucket.org/gwbasic/mongodb.emitter/">MongoDB.Emitter project page on bitbucket</a>.</p>
<h3>CSMongo</h3>
<p>Hugo Bonacci (<a href="http://twitter.com/hugoware">@hugoware</a>) 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.</p>
<p>I am looking forward to the next version which should have more features including support for Hugo’s own <a href="http://www.hugoware.net/projects/jlinq">jLinq</a>.</p>
<p>Code doesn't appear to be released yet but you can follow his progress at his blog, <a href="http://somewebguy.wordpress.com/2010/02/21/building-a-mongo-driver-part-1/">Hugoware</a>.</p>
<h3>simple-mongodb</h3>
<p>Simple-mongdb is another project without public source that is being worked on by Daniel Wertheim (<a href="http://twitter.com/danielwertheim">@danielwertheim</a>).  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.</p>
<p>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.</p>
<p>Check out the <a href="http://code.google.com/p/simple-mongodb/">simple-mongodb project page on Google Code</a>.</p>
<h3>DocumentConverter</h3>
<p>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.</p>
<p>Read more about <a href="http://deserialized.com/convert-csharp-classes-to-and-from-mongodb-documents-automatically-using-net-reflection">DocumentConverter on this blog post.</a></p>
<h2>Conclusion</h2>
<p>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.</p>
<p>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.</p>
<p><strong>If there are any more projects that I have missed – let me know in the comments!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://deserialized.com/c-sharp/the-state-of-mongodb-and-csharp/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

