I have a collection of data called users
stored in mongoDB that has the following structure:
_id: ObjectId,
sports: [
{
name: 'cricket',
history: [
{
from: 10,
to: 30
},
{
from: 30,
to: 30
}
]
},
// ... other sports as well
]
My goal is to query for users who have at least one element inside sports.history
where the condition from === to
is true. Each user can have multiple sports, each with its own history data.
I'm looking to achieve this filtering directly within the query, rather than fetching users and then applying the filter in my express app afterwards.
Any assistance on how to accomplish this would be greatly appreciated. Thank you!