I have a collection of documents, each containing an array of revenues of different lengths.
I want to get a single array of revenue from the values that match the query.
Example data
...
{"cohort": "2112", "revenue": [1, 1, 0, 0, 5], ...},
{"cohort": "2113", "revenue": [0, 0, 2, 0], ...},
{"cohort": "2114", "revenue": [0, 1, 3], ...}
...
Expected result for cohorts 2113 and 2114
[0, 1, 5] or [0, 1, 5, 0]
The two results are equal for my purpose, since I know the length of the shortest array.
Is there any way to perform the operation with MongoDB Aggregate pipeline?
Or can you suggest a better solution?
And yes, I use PyMongo to access the database.