I have the following aggregate:
db.reports.aggregate({ $group: { _id: "$user", reports: { $push: {report: {properties: "$properties"} } }}}, { $project: { _id: 0, user: "$_id", reports: "$reports"} })
I would like to somehow limit the number of reports that get pushed into the array. I.E I want to limit reports to a users defined value. 1,5,10 etc. Meaning I want N number of reports (I will sort by timestamp) to be included in the reports field. Right now I am pushing all reports not sure how to limit the number of reports per user.
I tried the $limit, but that didn't work as it restricted the number of users returned not the number of reports pushed into the reports array.
Basically I want to group my reports by user, and include only a certain number of reports. I would like to limit the number of reports as early as possible such that I do not have to deal with the entire collection throughout the pipeline