Skip to content

Instantly share code, notes, and snippets.

@2yk
Created May 8, 2019 06:22
Show Gist options
  • Select an option

  • Save 2yk/902c361f7dfcffbc874ca40ffe039582 to your computer and use it in GitHub Desktop.

Select an option

Save 2yk/902c361f7dfcffbc874ca40ffe039582 to your computer and use it in GitHub Desktop.

Revisions

  1. 2yk created this gist May 8, 2019.
    13 changes: 13 additions & 0 deletions query.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
       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]);