Convert LINQ to MongoDB queries to JavaScript shell

github_icon If you do a lot of work with MongoDB from .NET,
this code should look familiar:

var query =
        from p in mongo.People
        where p.Age > 20 && p.Name.Length >= 2
        orderby p.Age descending
        select p;

But could you answer these questions?

  • What *exactly* does it do on the server?
  • Is it using an index or not?

Well, I just released a new .NET library on GitHub

MongoDB query helper for .NET
https://github.com/mikeckennedy/mongodb-query-helper-for-dotnet

Now these questions are easy to answer. For example:

Console.WriteLine( query.ToMongoQueryText() );

outputs

{ "Age" : { "$gt" : 20 }, "Name" : /^.{2,}$/s }

Check it out. I hope you find it useful.

2 comments

Submit a comment

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s