Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View step1.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
var crimes = [
{"crime": "Assault", "property": "States Avenue"},
{"crime": "Larceny", "property": "Marvin Gardens"},
{"crime": "Assault", "property": "States Avenue"},
{"crime": "Motor Vehicle Theft", "property": "Boardwalk"},
{"crime": "Assault", "property": "States Avenue"},
{"crime": "Larceny", "property": "Marvin Gardens"},
{"crime": "Assault", "property": "States Avenue"},
{"crime": "Drugs", "property": "Marvin Gardens"},
{"crime": "Drugs", "property": "Marvin Gardens"},
{"crime": "Larceny", "property": "Marvin Gardens"},
{"crime": "Larceny", "property": "Marvin Gardens"},
{"crime": "Motor Vehicle Theft", "property": "Boardwalk"},
{"crime": "Motor Vehicle Theft", "property": "Boardwalk"},
{"crime": "Drugs", "property": "Marvin Gardens"}
]
 
if(db.crimes.count() == 0) {
crimes.forEach(function(c) {
db.crimes.insert(c)
})
}
 
 
function map() {
emit(this.property, 1)
}
 
function reduce(propKey, vals) {
var sum = 0
vals.forEach(function(v) {
sum += v
})
return sum
}
 
var mr = db.crimes.mapReduce(map, reduce),
results = db[mr.result].find()
printjson(result.toArray())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.