npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

mongo-map

1.0.0 • Public • Published

mongo-map

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

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

install

npm i mongo-map

Downloadsweekly downloads

1

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability