Serene Taleb-Agha Serene Taleb-Agha - 1 year ago 141
C# Question

Performance when using Filter.Where using the MongoDB C# driver

Say you have the following line of code:

var filter = Builders<BsonDocument>.Filter.Where(t => == myId);
var result = collection.Find(filter).ToList();

Does the filter builder translate the lambda to a literal $where clause or does it optimize it to use the $eq clause? $where has slow performance so I don't want to use it if there's no translation.

This is a simple example but we have other queries in our code that are lengthier but would easily translate to non-$where queries.

Answer Source

I have no idea. I will look into this tonight and come back to you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download