I am trying to write a mongoose query that can find all documents where REVIEW_DATE is within the last 24 hours and there is no action in the actions array that matches TYPE, DETAIL_TYPE, and ACTION_DATE does not match REVIEW_DATE. Basically if REVIEW_DATE changes, I need to re-perform the action, so the value of the review date is recorded in the actionDetails.
{
reviewDate: <REVIEW_DATE>,
actions: [
{
actionType: <TYPE>,
actionDetails: {
detailType: <DETAIL_TYPE>,
valueOfReviewDateAtTimeOfAction: <ACTION_DATE>
}
}
]
}
Because mongo doesn't support a self join, I am pulling back all documents where REVIEW_DATE is within the last 24 hours and then iterating through the results filtering the list by iterating over the list of actions. Is there a way do do this with a single query or aggregation?