Last active
December 29, 2020 15:37
-
-
Save anapaulagomes/18be9028e92b5033c0b4 to your computer and use it in GitHub Desktop.
Agrupa e calcula a média com aggregate - MongoDB
This file contains 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.zips.aggregate([ | |
{ | |
$match: { | |
$and : [ | |
{ $or: [ { state: 'XX' }, { state: 'YY' } ] }, { pop: {$gte: 25000}} | |
]} | |
}, | |
{ | |
$group: | |
{ | |
_id: null, | |
media: { $avg: '$pop'} | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
db.zips.aggregate([
{
$match: {
$and : [
{ $or: [ { state: 'XX' }, { state: 'YY' } ] }, { pop: {$gte: 25000}}
]}
},
{
$group:
{
_id: null,
media: { $avg: '$pop'}
}
}
])