Skip to content

Instantly share code, notes, and snippets.

@h2rd
Created December 3, 2012 11:11
Show Gist options
  • Select an option

  • Save h2rd/4194243 to your computer and use it in GitHub Desktop.

Select an option

Save h2rd/4194243 to your computer and use it in GitHub Desktop.
mongo get total population where the city starts with a digit
use test
db.zips.aggregate([
{ $project: {
first_char: {$substr : ["$city",0,1]},
pop: 1
}
}, { $match: {
first_char: /[0-9]/
}
}, { $group: {
_id: "Total",
total: { $sum: '$pop' }
}
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment