Skip to content

When using mongoDB aggregation framework, this helper lets you make a lookup in a JS-map

Notifications You must be signed in to change notification settings

debitoor/mongo-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongo-map npm version Build Status devDependency Status

When working with mongoDB Aggregation Framework sometimes you need to transform a field based on plain js map object. Consider you have:

var map = {
	forThisKey: 'retrun this value',
	thisKeyEqualsTo: 'something like this',
	andForThisOne: 'return some other string'
};

In regular js code you would do:

var value = map[key];

This module helps you do the same inside aggregation framework pipeline.

npm install mongo-map

Requirements

  • mongo 2.6.x or higher

Usage

var getInMap = require('mongo-map');

db.myCollection.aggregate([
	{ $project: {
		value: getInMap(map, '$key')
	} }
]);

Here getInMap expands your map object into a balanced search tree that aggregation framework uses to efficiently look up your key.

License

MIT

About

When using mongoDB aggregation framework, this helper lets you make a lookup in a JS-map

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published