My query retus a list of objects -- each of which are test reports. A test report contains a unitId indicating which test unit produced the result. My goal is to gather the most recent report for each unit and filter out all of the older reports.
Example:
The query might look something like this:
db.getCollection('tests').find({'model' : 'roboticArm'}).sort({'endTime' : -1})
I have gathered all of the tests performed on the roboticArm model and sorted them according to 'endTime'. Inteally we have many robotic arms units we use for testing -- say 100. Of the thousands of tests performed I only want to see the most recent test for each unit (marked by the 'unitId' key).
How do I structure a query like that? Is there a way to do this with aggregation?
