I have a data model that keeps track of different activities, including any problems or errors:
activities?: {
message?: string;
data?: any;
issue?: {
errors?: AVError[];
dismissed?: {
timestamp: string;
message?: string;
};
}
}[];
I am looking to retrieve records that do not have any unresolved issues in the activities section.
Every attempt I've made so far has not been successful. The latest query I tried is:
collection.find({
activities: {
$not: {
$elemMatch: {
issue: { $exists: true },
'issue.dismissed': { $exists: false },
},
},
},
});
This query works for cases where there are no reported issues or when all issues are resolved, but it fails to identify records with unresolved issues.
Another approach I attempted was:
collection.find({
$or: [
{ 'activities.issue': { $exists: false } },
{
'activities.issue': { $exists: true },
'activities.issue.dismissed': { $exists: true },
},
],
});
Unfortunately, this method also missed some records with dismissed issues.
While I can manually filter the results after retrieving all the data, I believe there should be a way to handle this within a single Mongoose query.