Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/debitoor/mongo-map
When using mongoDB aggregation framework, this helper lets you make a lookup in a JS-map
https://github.com/debitoor/mongo-map
Last synced: 12 days ago
JSON representation
When using mongoDB aggregation framework, this helper lets you make a lookup in a JS-map
- Host: GitHub
- URL: https://github.com/debitoor/mongo-map
- Owner: debitoor
- Created: 2015-04-21T14:10:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-04-23T09:26:26.000Z (over 9 years ago)
- Last Synced: 2024-11-01T21:05:28.422Z (16 days ago)
- Language: JavaScript
- Size: 156 KB
- Stars: 3
- Watchers: 46
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
mongo-map [![npm version](https://badge.fury.io/js/mongo-map.svg)](http://badge.fury.io/js/mongo-map) [![Build Status](https://travis-ci.org/e-conomic/mongo-map.svg?branch=master)](https://travis-ci.org/e-conomic/mongo-map) [![devDependency Status](https://david-dm.org/e-conomic/mongo-map/dev-status.svg)](https://david-dm.org/e-conomic/mongo-map#info=devDependencies)
=========When working with [mongoDB Aggregation Framework](http://docs.mongodb.org/manual/aggregation) sometimes you need to transform a field based on plain js map object. Consider you have:
```javascript
var map = {
forThisKey: 'retrun this value',
thisKeyEqualsTo: 'something like this',
andForThisOne: 'return some other string'
};
```
In regular js code you would do:
```javascript
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
```javascript
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](http://opensource.org/licenses/MIT)