Skip to content

Instantly share code, notes, and snippets.

@anapaulagomes
Last active December 29, 2020 15:37
Show Gist options
  • Save anapaulagomes/18be9028e92b5033c0b4 to your computer and use it in GitHub Desktop.
Save anapaulagomes/18be9028e92b5033c0b4 to your computer and use it in GitHub Desktop.
Agrupa e calcula a média com aggregate - MongoDB
db.zips.aggregate([
{
$match: {
$and : [
{ $or: [ { state: 'XX' }, { state: 'YY' } ] }, { pop: {$gte: 25000}}
]}
},
{
$group:
{
_id: null,
media: { $avg: '$pop'}
}
}
])
@mqfabio
Copy link

mqfabio commented Dec 29, 2020

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