Consider this scenario: I wanted to fetch the filtered document from the documents collection of Student.
[
{
name:'arun',
gender:'Male',
physics:88,
maths:87,
english:78
},
{
name:'rajesh',
gender:'Male',
physics:96,
maths:100,
english:95
},
{
name:'moorthy',
gender:'Male',
physics:89,
maths:90,
english:70
}]
I wanted to filter based on array having value as
[
{
name:'arun',
gender:'Male',
physics:88,
maths:87,
english:78
},
{
name:'rajesh',
gender:'Male',
physics:96,
maths:100,
english:95
}]
And I wanted to match name, gender and physics to get the filtered documents. I don't want to use foreach. How can I get a filtered list of documents?
This query will be slightly tricky as it requires matching any item and at the same time, all the properties in the item must be matched.
Demo @ Mongo Playground
In the MongoDB .NET way, you need to prepare the filter definition matching all the properties in the
studentfirst and add it intofilterDefinitions. Next, withOrbuild the query that matches any item infilterDefinitions.