Skip to content

Instantly share code, notes, and snippets.

@hperantunes
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hperantunes/b06073819eb953a6d7a8 to your computer and use it in GitHub Desktop.
Save hperantunes/b06073819eb953a6d7a8 to your computer and use it in GitHub Desktop.
db.zips.aggregate([
{$match: {$or: [{state: 'CT'}, {state: 'NJ'}]}},
{$group: {_id: {state: '$state', city: '$city'}, pop: {$sum: '$pop'}}},
{$match: {pop: {$gt: 25000}}},
{$group: {_id: null, avg: {$avg: '$pop'}}}
])
db.zips.aggregate([
{$match: {$or: [{state: 'CA'}, {state: 'NY'}]}},
{$group: {_id: {state: '$state', city: '$city'}, pop: {$sum: '$pop'}}},
{$match: {pop: {$gt: 25000}}},
{$group: {_id: null, avg: {$avg: '$pop'}}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment