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.

Michael Kennedy

A Python enthusiast and an entrepreneur. Host of Talk Python and Python Bytes podcasts, founder of Talk Python Training. Python Software Foundation Fellow.

Tags:

2 comments

Submit a comment