Mongo C# driver 2.0 is not as evil as it sounds

What got me too , and perhaps must have got you as well was that the C# driver 2.0 for Mongo was actually a bit of odd ball! There is so much decry over the fact that the driver allows only async methods is that you start believing it could really be evil afterall!

A bunch of developers are complaining that “async-only” APIs would mean you have performance hit rather than gain since the number of threads is actually not even considerable. Yeah agreed! – thread cleaning and management in cases of lesser loads means it is rather slower. But ask a guy like me who has used ORM (Object relational mapping) and LINQ over SQL server, Mongo C# (despite async-only) is a pleasure !

People who have not worked with asynchronous programming are most likely to to find this a bit odd , but that ‘s as far it can go. Slightly sour for the regular taste buds , until once you gulp it down you would actually start enjoying.

public async Task<IEnumerable<OfType>> function(){

var task = MongoClient.GetCollection(“name of the collection”).Find(filter).ToListAsync( );

//happy to do all the independent stuff here , while the database would get me results.

await task;

return task.Result; //this result is expected to be an enumerable


was that any twisted ? Not at all !!

Rather the fact that this has done away with Entity Framework  / ADO.NET pain is like a delight. The async statement is not even a concern for me. Yeah perhaps a bit un-natural but not as tedious as this in EF ..

This is how I would get things from SQL EF over LINQ

public  IEnumerable<ofType> GetFunction(){

using(dataContext  db = new dataContext){

db.Entities.Where(Predicate filter).Select(x=>x).toArray( );



the innocent looking SQL LINQ code above has a draconian EF ORM model behind the scenes.

  • Objects from the ORM are not directly serializable in case you are using database first scaffolding. So then Serializable business models and ORM models then need to be fungible. Alas! -sheer agony of writing object conversion code.
  • code-first scaffolding obviously needs a lot of effort, not that Mongo does not have POCO business models, but the pain of synchronizing the model with the tables and the relations is serious.

Mongo – no tables, no relations, no PK-FK, and hence no FK violations. That to me is such a relief ! Who cares if it is async APIs or Sync APIs ..


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

Create a free website or blog at

Up ↑

%d bloggers like this: