My goal is to filter out records that have already been matched in a previous MongoDB aggregation.
In the first match, I want to retrieve records from two countries: United States and Germany.
In the second match, I want to exclude records from a specific country, such as United States, where the level is "Beginner", while still keeping other records from United States and Germany. How can this be achieved? Example Data:
[
{
country: 'United States',
personName: 'John',
level: 'Average',
},
{
country: 'United States',
personName: 'Rina',
level: 'Beginner',
},
{
country: 'Germany',
personName: 'John',
level: 'Average',
}
]
First match (correct):
{
country: {$in: ['United States', 'Germany']}
}
Second match (incorrect):
{
$and: [
{ level: { $ne: 'Beginner'} },
{ country: { $eq: 'United States' } },
]
}
I do not want to re-add the countries array in the second match phase.