Filter Builder
noun
say it: “FIL-ter BIL-der” /ˈfɪltər ˈbɪldər/
In MongoDB's C# driver, the object whose methods, such as Eq and Lte, build a query filter one condition at a time.
What is the filter builder in MongoDB's C# driver?
The filter builder, Builders<T>.Filter, is how MongoDB's C# driver writes a filter: one method per condition, such as Eq for an exact value and Lte for "less than or equal to", joined with & (and) or | (or). The compiler checks the field names.
var filter = Builders<Pet>.Filter.Eq(p => p.Species, "cat")
& Builders<Pet>.Filter.Lte(p => p.Age, 3);
var youngCats = await pets.Find(filter).ToListAsync();
In a sentence
- “With the filter builder, a typo in a field name is a build error instead of an empty result.”
- “The filter builder turned { species: "cat", age: { $lte: 3 } } into C# the compiler can check.”
Level: Journeyman · More MongoDB terms at this level
Updated