Thoughts on user experience, business and technology for search

by DotNetNerd 18. November 2012 14:07

Lately I have been working quite a bit with search, and have two customers going live with new sites in the comming months. Along with doing the actual implementations I wrote a (danish) whitepaper on search back in september, and I have read a couple of books to really get into the topic. Search patterns from O’Reilly is a really good book, if you need non-technical inspiration on how search can be done. Having spent some time on the subject, I have of course developed some opinions on both the uability and technical aspects, which is the reason I am writing this post.


Implementing faceted search with MongoDB

by DotNetNerd 8. December 2011 08:29

After my last post on the faceted search I was asked to elaborate on how it was implemented with MongoDB. So that is just what I will do with this post – giving me the chance to comment a bit on the good and the bad experiences. Even though it was a good overall experience, there will always be things to wish for – the day I say otherwise is the day I should stop being a developer.


MongoDB – getting better for .NET

by DotNetNerd 6. March 2010 16:24

Since my last post Rob Connery has joined the team working on MongoDB, and he recently blogged about the latest additions he has made on github. I couldn’t resist taking a look at the latest changes, and even though there is still some way to go it is nice to see the improvements to the drivers for .NET.

My last sample is already depricated, so Ill shamelessly steal his sample, and modify it slightly just to see the new bits running with entities that I worked with last. So Ill recommend looking at the sample from the blogpost, since I’ll be using his session class.

First thing to notice from Robs sample is that I don’t have to think much about mapping classes to documents any longer. One thing that is already depricated even from Robs own sample is that it is now a requitement that the class has an identifier. So going with the simplest thing possible I added an ID integer.

using (var session=new Session()){
   session.Add(new Actor { ID = 1, Name = "Hans", Age = 40, Gender = Gender.Male });
   session.Add(new Actor { ID = 2, Name = "Eva", Age = 22, Gender = Gender.Female });

So comparing to Db4o, we are now closer to a similar experience. One of the things I’ll wait to look at, but I see as fairly importait is how either will handle Lazy<T> properties and other kinds of more advanced scenarios.

With the above objects saved the data can be accessed using a Linq query like so:

using (var session=new Session())
   var actors = session.Actors;
   foreach (var actor in actors.Where(a => a.Gender == Gender.Male))

The LINQ provider is still not too far along so I’ll leave it alone for now, but it is also one of the places where it will be interesting to compare e.g. db4o and MongoDB in the future.

Tags: ,

Ayende - the relational dragonslayer

by DotNetNerd 23. February 2010 18:31

Ayende, who most know to be one of the Guru's when talking about ORM's and by extention working with relationel databases came to a very interesting conclusion a couple of days ago when he received a phonecall. To parafrase his point in "Slaying relational dragons" in a few words, a very real and complex problem had one very simple and elegant solution - do not use a relational database. This acknowledgement is as a see it a strong incentive to take a look at what NOSQL solutions like document and object based databases has to offer. And his blogpost is something I would definitely recomment reading...


Tags: ,

Db4o – first look

by DotNetNerd 21. February 2010 13:12

As the next step in my recent adventures into NoSQL country I decided to take a look at db4o. Shortly put I hope it will give me more than the document based databases, like Mongo that I have also been taking out for a spin.

My interest in NoSQL has been kindled further than it already was because of blog posts from Rob Connery, who looked into practical approaches and posts on CodeBetter provokingly entitled Using an ORM is like kissing your sister. Basically what they are all saying is that it is very limiting that we always start out with a relational database without even considering this very very important architectural decision.

Object vs Document

Similar to the document based database, the big win is that there is no schema, and no need to map between objects and a relational model. Actually with document based databases you do map to key/value pairs, so it’s not the whole truth, but still simpler than mapping to a relational model.

Mapping can be expensive in two ways – because it takes time to write the code, and it does warrant a certain overhead. On top of that db4o as an object oriented database has a concept of relations between objects. This means that rich querying capabilities are build in and that it performs really well.

When comparing to MongoDB the big thing missing is that it basically works on a flat file out of the box. So you need something to handle concurrency and stuff like that. Rob Connery posted a nice sample of how this could be done, and its really quite straight forward, because db4o does provide all you need to do it.

The basic stuff

In the interest of simplicity I’ll just sample how to work with db4o directly. Also this will illustrate just how straight forward it really is. The first thing that brought a smile to my face was how little I had to do to save and query a bunch of objects.

using (IObjectContainer context = Db4oEmbedded.OpenFile(Server.MapPath("myDatabase.yap")))
    var empolyeeToSave = new Employee() { Name = "John", Card = new TaxCard() { Number = "12345678" } };

    IList<Employee> retrievedEmployees =
        context.Query<Employee>(employee => employee.Card.Number == "12345678");


As you can see it’s very straightforward stuff. Besides this type fo querying which takes a predicate, there is also a QueryByExample, which works as one would expect. Another nice thing is that all calls to the Store method make up a transaction, so there is a Rollback method available. When the context is disposed the convention is that Commit is called for you, so when you don’t need rollbacks you don’t have to think about it.

Indexing is also possible with db4o, and it is also very simple to do, so if for instance I would like to apply an index for the name property on my Employee I could do this.


Moving along

Some of the first things that I have heard people think about when I say object/document based database is how to handle versioning and querying. With querying in this case I mean how to enable a scenario similar to opening SQL Manager and writing some queries to take a look at the actual data.

The versioning part may take a little work, but there are methods to help with e.g. renaming directly baked in - and besides, it takes work no matter what kind of database your using. On top of that my thought is that both of these issues can be addressed with a dynamic language. My plan is to take a look at this at some point, and that it will fit nicely because my copy of IronRuby Unleashed should be on it’s way :)


Tags: ,

MongoDB – how to get started

by DotNetNerd 3. January 2010 11:17

Even though I have been pretty disconnected during the holydays I couldn’t help read that Rob Conery wrote quite a bit on his blog about his thoughts on Ayendes “EF vs NHibernate” discussion. Rob Conery argues that he is tired of these discussions and that we need to look at the NOSQL movement and instead focus on alternatives to relational databases.

I found this pretty interesting and decided that it was finally time for me to take a look at one of the document based databases out there. As Rob mentioned MongoDB I thought this was a good a place to start as any. Based on my experiences I then decided to do this post on what I learned about getting MongoDB up and running. So first of all, the steps to get a MongoDB server running are:

  1. Download and unpack from:
  2. Create folder C:\data\db and make sure the server has read and write access
  3. Run the server from cmd. Go to dir where you unpacked (eg: "c:\MongoDB\bin") and run "mongod"

You can now work with the database from the commandline, but to start writing some code you need to get a driver that suits you. In my case I went with a driver so I can write my code in C#. This driver along with a early edition of a LINQ library can be downloaded from 

This is all you need to get going, so just create a new project and start coding!

A good sample can be found here and if your into F# this might be interesting

The first sample focuses on two ways to handle converting objects into documents.

  1. Serialize object(hierarchy) into JSon using JSonConverter - which was the sample I focused on.
  2. Make entities implement the IMongoEntity interface – which basically just makes your entity expose a Document property which then contains the state for the entity.

Of course I wont cheat you from seeing the bit of code I started out with, which is heavily inspired by the before mentioned blog posts.

//Connect to the database
var mongo = new Mongo();
var db = mongo.getDB("movieReviews");

//Access the collection that you wish to work with
var movies = db.GetCollection("movies");

//Add a document
var movie = new Document();
movie["title"] = "Star Wars";
movie["leadActor"] = JsonConvert.SerializeObject(
 new Actor() {Name = "Mark Hamill", Age = 26, Gender = Gender.Male});
movie["releaseDate"] = new DateTime(1977, 5, 25);

//Do a query
var result = from mov in movies.AsQueryable()
             where (string)mov["title"] == "Star Wars"
             select mov;

//Write out info from document
foreach (var document in result)
 foreach (string key in document.Keys) Console.WriteLine(document[key]);

//Deserialize and write name

//Disconnect from database


You'll also need this simple class for the sample:

public class Actor
 public string Name { get; set; }
 public int Age { get; set; }
 public Gender Gender { get; set; }

public enum Gender
 None = 0,
 Male = 1,
 Female = 2

Tags: ,

Who am I?

My name is Christian Holm Diget, and I work as an independent consultant, in Denmark, where I write code, give advice on architecture and help with training. On the side I get to do a bit of speaking and help with miscellaneous community events.

Some of my primary focus areas are code quality, programming languages and using new technologies to provide value.

Microsoft Certified Professional Developer

Microsoft Most Valuable Professional

Month List