MapReduce with MongoDB in NodeJS
✓ Published0🌍 Public
Aackuser
Last edited Dec 4, 2011
Created on Oct 27, 2016
This example demonstrates a MapReduce operation in MongoDB, executed from a Node.js application, that aggregates sensor measurements into hourly averages per user and device. The code defines custom `map`, `reduce`, and `finalize` functions to group raw data points by a composite key of user email, device UID, and the hour timestamp, then computes a weighted average value and total weight. The operation queries MongoDB’s `Measure` collection, merges results into an output collection named `measure1hs`, and reports execution statistics via a callback. The implementation uses MongoDB’s native `db.Measure.collection.mapReduce` API directly, bypassing Mongoose, and handles asynchronous completion through a callback function.
AI-generated description