I couldn’t measure this on my own, so can someone explain what is more performant (faster) and best practice.
Match filter that I use now is
var = Builders<MyObject>.Filter.Gte(x => x.DocumentDate, fromTimestamp)
& Builders<MyObject>.Filter.Lte(x => x.DocumentDate, toTimestamp)
& Builders<MyObject>.Filter.ElemMatch(x => x.Customer, x => x.Customer == 1)
& Builders<MyObject>.Filter.ElemMatch(x => x.Language, x => x.LanguageShort == "en")
& Builders<MyObject>.Filter.ElemMatch(x => x.SomeArray, Builders<MyArrayObject>.Filter.In(i => i.SomeProperty, arrayOfValuesToMatch));
Property DocumentDate
is ONLY indexed in my document (so in matchFilter
I combine indexed and not indexed properties)
When writing aggregations like
var results = await Collection.Aggregate()
.Match(matchFilter)
.Project(someProjectionFilter)
.ToListAsync();
is it better to have two matches, one following other, like
var results = await Collection.Aggregate()
.Match(match-filter-with-indexed-properties)
.Match(match-filter-NOT-indexed-properties)
.Project(someProjectionFilter)
.ToListAsync();
where first match would match only indexed properties, and second match would match unindexed properties.
Please note that adding extra indexes is not an option, since I have many different filters, where DocumentDate
is common one.
Ty,
Marko