Gist 737033
✓ Published0🌍 Public
CCaged
Last edited Dec 11, 2010
Created on Dec 11, 2010
This example demonstrates a MapReduce aggregation over a MongoDB collection of crime records, showing the count of crimes grouped by property name. The code first seeds a `crimes` collection with sample data, then defines a `map` function that emits each property name with a value of 1, and a `reduce` function that sums the emitted values. The MapReduce operation runs via `db.crimes.mapReduce()` and outputs the results as a JSON array using `printjson`. It uses MongoDB’s JavaScript shell API for data insertion, mapping, reduction, and result retrieval.
AI-generated description