Skip to content

@Caged /step1.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.