# mongo-project

> Simplified Mongo DB style projection for hiding/showing specific fields.

Latest version **1.0.1** (published 2017-06-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongo-project
pnpm add mongo-project
yarn add mongo-project
bun add mongo-project
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-06-28 |
| First published | 2017-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 7.0.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | patrick.d@ventral.org |
| Maintainers | patrickd- |
| Keywords | mongo, mongodb, project, projection, object, hide, mask, map, field |

## Links

- npm: https://www.npmjs.com/package/mongo-project
- Repository: https://github.com/patrickd-/mongo-project.node
- Homepage: https://github.com/patrickd-/mongo-project.node/
- Issues: https://github.com/patrickd-/mongo-project.node/issues
- npm.io page: https://npm.io/package/mongo-project

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-06-28
- 1.0.0 — 2017-05-29

## README

# mongo-project

[![Build Status](https://travis-ci.org/patrickd-/mongo-project.node.svg?branch=master)](https://travis-ci.org/patrickd-/mongo-project.node) [![Coverage Status](https://coveralls.io/repos/github/patrickd-/mongo-project.node/badge.svg)](https://coveralls.io/github/patrickd-/mongo-project.node) [![Dependencies Status](https://david-dm.org/patrickd-/mongo-project.node.svg)](https://david-dm.org/patrickd-/mongo-project.node)

Simplified [MongoDB style projection](https://docs.mongodb.com/manual/reference/method/db.collection.find/#projection) for hiding/showing specific fields.

```
npm install mongo-project
```

## Usage

### Hide some fields from an object

```javascript
const project = require('mongo-project');

const object = {
  title: 'Bar title',
  author: {
    name: 'Foo Person',
    email: 'foo.person@example.com',
  },
};

const projectedObject = project(object, {
  'author.email': 0,
});

console.dir(projectedObject);
// {
//   title: 'Bar title',
//   author: {
//     name: 'Foo Person'
//   }
// }
```

### Only show specific fields of an object

```javascript
const project = require('mongo-project');

const object = {
  title: 'Bar title',
  author: {
    name: 'Foo Person',
    email: 'foo.person@example.com',
  },
};

const projectedObject = project(object, {
  'title': 1,
  'author.name': 1,
});

console.dir(projectedObject);
// {
//   title: 'Bar title',
//   author: {
//     name: 'Foo Person'
//   }
// }
```

### More complex examples can be found in the [tests](test/projectSpec.js).

### $, $elemMatch, $slice, $meta

The [operators of MongoDBs](https://docs.mongodb.com/manual/reference/method/db.collection.find/#projection) projection are not supported.

---
_Source: https://npm.io/package/mongo-project · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
