Created
May 8, 2019 06:22
-
-
Save 2yk/902c361f7dfcffbc874ca40ffe039582 to your computer and use it in GitHub Desktop.
Mongo Group by Month Query Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const match = { | |
$group: { | |
_id: { month: { $month: '$createdAt' } }, | |
count: { $sum: 1 }, | |
}, | |
}; | |
const group = { | |
$group: { | |
_id: null, | |
patient: { $push: { month: '$_id.month', count: '$count' } }, | |
}, | |
}; | |
return Zone.aggregate([match, group]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment