
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
node-mapred
Advanced tools
Map Reduce implementation of mongodb for nodejs
This lib would help you to apply mongodb mapReduce operation on array of objects
npm i node-mapred --save
var MapRed = require("node-mapred");
var mapred = new MapRed();
var info = [{
type: "fruit",
name: "apples",
qty: 21
}, {
type: "fruit",
name: "mangoes",
qty: 23
}, {
type: "fruit",
name: "apples",
qty: 2
}, {
type: "fruit",
name: "mangoes",
qty: 3
}, {
type: "animal",
name: "dogs",
qty: 3
}, {
type: "animal",
name: "cats",
qty: 3
}, {
type: "animal",
name: "dogs",
qty: 7
}]
mapred.exec(info)
.map(function () {
mapred.emit(this.name, this.age)
})
.reduce(function (key, values) {
return values.reduce((sum, val) => sum + val);
})
.result(function (result) {
console.log(result);
// Output [ { _id: 'apples', value: 23 }, { _id: 'mangoes', value: 26 } ]
})
mapred.exec(info)
.map(function () {
var self = this
var key = {
type: self.type,
name: self.name
}
mapred.emit(key, this.qty)
})
.reduce(function (key, values) {
return values.reduce((sum, val) => sum + val);
})
.result(function (result) {
console.log(result);
// Output
// [ { _id: { type: 'fruit', name: 'apples' }, value: 23 },
// { _id: { type: 'fruit', name: 'mangoes' }, value: 26 },
// { _id: { type: 'animal', name: 'dogs' }, value: 10 },
// { _id: { type: 'animal', name: 'cats' }, value: 3 } ]
})
npm install
npm test
MIT
FAQs
Map Reduce implementation of mongodb for nodejs objects
We found that node-mapred demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.