Answer the question
In order to leave comments, you need to log in
How to quickly get a large number of documents by a variety of criteria?
You need to select N documents based on M predicates, where M can be several hundred pieces (up to 1000).
The method input receives an array of filters filters, by which you need to select documents from Monga.
public async Task<IEnumerable<DataDto>> GetDataAsync(IEnumerable<Expression<Func<DataDto, bool>>> predicates)
{
var filters = predicates.Select(p => new FilterDefinitionBuilder<DataDto>().Where(p));
var filter = new FilterDefinitionBuilder<DataDto>().Or(filters);
var result = await collection.FindAsync(filter) .ConfigureAwait(false);
return result.ToList();
}
a => a.Source.ID == filter.Source
&& a.Dest.ID == filter.Dest
&& a.Type == filter.Type
&& a.Date >= filter.MinDate && a.Date <= filter.MaxDate
&& ...;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question