Relative Content

Tag Archive for mongodbaggregation-framework

MongoDb $lookup through array and aggregate

Below are two collections orders and amounts. I have array of lookup data which is to be added using $addFields in orders aggregate pipeline and iterated and get total amount sum from amounts collections.

Create a Dashboard View from a customer’s list

I have a collection where I store customers with their info from multiple other collections.
I need to organize a document where the yearly info is separated by year, starting from 2020 until the current year (so next year, it will still works).
Then, for each year, I need to perform some checking to get the info/status for each array item.
If the customer checks true for the specific yearly Item, I have to add it’s _id into a sub-array in the resulting query.
Here is a sample of my customers collection: