Last active
October 22, 2020 15:30
-
-
Save adnan-i/d82a956d67c153b5efc8 to your computer and use it in GitHub Desktop.
Revisions
-
adnan-i revised this gist
Feb 11, 2015 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,13 @@ User.aggregate([ { /* Filter out users who have not yet subscribed */ $match: { /* "joined" is an ISODate field */ 'subscription.joined': {$ne: null} } }, { /* group by year and month of the subscription event */ $group: { _id: { year: { @@ -18,6 +20,7 @@ } }, { /* sort descending (latest subscriptions first) */ $sort: { '_id.year': -1, '_id.month': -1 -
adnan-i created this gist
Feb 11, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ .aggregate([ { $match: { /* "joined" is an ISODate field */ 'subscription.joined': {$ne: null} } }, { $group: { _id: { year: { $year: '$subscription.joined' }, month: { $month: '$subscription.joined' } }, } }, { $sort: { '_id.year': -1, '_id.month': -1 } }, { $limit: 100, }, ])