Seperate indexed from unindexed properties in match filter

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()

is it better to have two matches, one following other, like

var results = await Collection.Aggregate()

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.


Hello @Marko_Saravanja,

No, it is not. The query operation doesn’t change if you have your filter spread over multiple $match stages or with a single $match stage. It doesn’t affect your query performance either.

Further explained in the sub-topic $match + $match Coalescence:


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.