Skip to content

Instantly share code, notes, and snippets.

@jonhinson
Created May 8, 2011 19:50
Show Gist options
  • Save jonhinson/961637 to your computer and use it in GitHub Desktop.
Save jonhinson/961637 to your computer and use it in GitHub Desktop.
Count number of listings per city in a given state.
db.$cmd.findOne({group : {
ns : "listings",
cond : { state: "TX"},
key : {state : 1, city_slug: 1},
initial : {count : 0},
$reduce : function(obj,prev){prev.count++;}}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment