Last active
December 31, 2015 20:58
-
-
Save glpunk/8043266 to your computer and use it in GitHub Desktop.
mongodb aggregate example. First query counts documents by country. Second, counts documents by date
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
db.contests_tbbt2013.aggregate( | |
{ $group: {_id: "$country", total: {$sum: 1} } } | |
); | |
db.contests_tbbt2013.aggregate( | |
{$group: | |
{ | |
_id:{ $dayOfYear:'$regdate' }, | |
sum:{$sum:1}, | |
date:{$first: '$regdate'} | |
} | |
}, | |
{ $sort : { date:1 } } | |
); | |
db.schedules.aggregate( | |
{$group: | |
{ | |
_id:{ $dayOfYear:'$start' }, | |
sum:{$sum:1}, | |
date:{$first: '$start'} | |
} | |
}, | |
{$match:{date: {$gte: new Date('jan 17,2014')}}}, | |
{ $sort : { date:1 } }, | |
{$limit: 15} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment