Simple-MongoDB – Alpha version is out

Ok, it’s finally out. My driver agains MongoDB can be downloaded from:

I will try to write more about how to use it, in the next couple of days, but for now I will just double post the info that’s posted on the Google code site.

A C# implementation of a driver that can be used to communicate with MongoDB. The focus lies in keeping it “dynamic” by using anonymous types and JSON.

  • No need of extending a certain base-class.
  • No need for mappings.
  • No need for using key-value dictionaries, it’s up to you
  • Does relly on Db for Id-generation (the Id is for the Db, you should focus on business keys)
  • Using a well known JSON/BSON-serializer (


  • Authorization
  • DbRef
  • Grid
  • Simplify Querying
  • RegularExpressions
  • Documentation
  • API

    The API comes in two flavours: one where you directly consume commandobjects (insert, update, delete, query);and one where this is abstracted away, where you instead use a session with hierarchies.

    Some simple examples of how the API currently looks like (it’s an alpha release so the API will probably have some changes).


    To work with Simple-MongoDb you need to establish a connection to a MongoDb-server. This is done by creating an instance of SimoConnection (simo = Simple-MongoDb). The SimoConnection needs to know: address and port of the server. This is wrapped in SimoConnectionInfo, which could be populated manually or via connectionstring-name:

    var cn = new SimoConnection(new SimoConnectionInfo(Constants.ConnectionStringName));
      <add name="SimpleMongoDbTests" connectionString="host:localhost;port:27017"/>

    Below I have wrapped this in a factory-method CreateConnection().


    var document = new { Name = "Daniel", Age = 29 };
    using (var cn = CreateConnection())
        var insertCommand = new InsertDocumentsCommand(cn)
            FullCollectionName = "TestDb.Persons",
            Documents = new[] { document }


    var document = new { Name = "Daniel", Age = 29 };
    using (var session = new SimoSession(CreateConnection()))

    Querying could be done in a numerous ways(not yet regexs, it’s on the roadmap).

  • Json: var query = @"{Age : 29}"
  • Json: var query = @"{$where: ""this.Name == 'Daniel' && this.Age == 29""}"
  • Anonymous type: var query = new {Name = "Daniel"}
  • Typed: var query = new Person {Name = "Daniel"}
  • WhereOperator: See below
  • using (var session = new SimoSession(CreateConnection()))
        var persons = session[DbName][PersonsCollectionName]
            .Find<Person>(new WhereOperator("this.Age > 20 && this.Age < 65"));


    2 thoughts on “Simple-MongoDB – Alpha version is out

      • My project is a result of using Sam Corder’s driver (the one that you mention). It’s a great product. The things I wanted to change was to remove the tight coupling to a single class like Document (which was something I did if you check at my earlier writings). I want to be able to use anonymous types, static types as well as json without having to inherit or extend some certain class. I also wanted to make use of the existing Json/Bson.Net library for dealing with BSON and JSON.


    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s