In the Mongo docs on materialized views i saw this example:
updateMonthlySales = function(startDate) {
db.bakesales.aggregate( [
{ $match: { date: { $gte: startDate } } },
{ $group: { _id: { $dateToString: { format: "%Y-%m", date: "$date" } }, sales_quantity: { $sum: "$quantity"}, sales_amount: { $sum: "$amount" } } },
{ $merge: { into: "monthlybakesales", whenMatched: "replace" } }
] );
};
I wanted to understand
- where do I write this function,
- and how I can invoke it
It would be extra amazing if anyone has a solution from a Play-Framework/Reactive Mongo pov.
Any help would be very much appreciated