I want to run an aggregation pipeline, use the result as filter to find a document and update it.
My schema has three fields : name, shiftWorked, eligible.
- I want to find an employee who has worked at least 10 shifts (should have 10 entries against his name) and should not have worked more than 5 shifts in last 3 days.
- This will give me certain employee names.
- i want to pick first such eligible employee and mark him as eligible.
Please pardon my ignorance, i am super new to mongoDB, but I think I’ll need two aggregations, first will filter the employees based number of shifts worked and second will filter it further to makes sure employee has not worked more than 5 shifts in last three days.
If i can get these name in a query, I can use findOneAndUpdate to pick one such employee and mark him as eligible.
Just wanted to know what is the best way to go about this?