Weekly Monthly Data Sum and Avg Example
$group :- Groups input documents by the specified _id expression and for each distinct grouping, outputs a document.
The _id field of each output document contains the unique group by value.
The output documents can also contain computed fields that hold the values of some accumulator expression.
_id : It is Required. If you specify an _id value of null, or any other constant value, the $group stage calculates accumulated values for all the input documents as a whole.
$avg : Returns an average of numerical values. Ignores non-numeric values.
$sum : Returns a sum of numerical values. Ignores non-numeric values.
$month : Returns the month of a date as a number between 1 and 12.
{ $month: new Date("2016-01-01") }
$week: Returns the week of the year for a date as a number between 0 and 53.Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. Days preceding the first Sunday of the year are in week 0.
{ $week: new Date("Jan 1, 2016") }
Reference link For $week : https://docs.mongodb.com/manual/refer...
Reference link For $month : https://docs.mongodb.com/manual/refer...
Reference link For $group :
https://docs.mongodb.com/manual/refer...