Skip to content

Instantly share code, notes, and snippets.

@shadedyin
Created March 18, 2014 03:58
Show Gist options
  • Save shadedyin/9613310 to your computer and use it in GitHub Desktop.
Save shadedyin/9613310 to your computer and use it in GitHub Desktop.
db.People.aggregate({
$group : {
_id : { street: "$STREET_NAM", area: "$AREA", ward: "$WARD", precinct: "$PRECINCT" },
street_min : { $min : "$STREET_NO" },
street_max : { $max : "$STREET_NO" },
black : { $sum : { $cond : [ { $eq : [ "$RACE", "B" ] }, 1, 0 ] } },
white : { $sum : { $cond : [ { $eq : [ "$RACE", "W" ] }, 1, 0 ] } },
other : { $sum : { $cond : [ { $eq : [ "$RACE", "O" ] }, 1, 0 ] } },
hispanic : { $sum : { $cond : [ { $eq : [ "$RACE", "H" ] }, 1, 0 ] } },
total : { $sum : 1 }
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment