mongo-project

1.0.1 • Public • Published

mongo-project

Build Status Coverage Status Dependencies Status

Simplified MongoDB style projection for hiding/showing specific fields.

npm install mongo-project

Usage

Hide some fields from an object

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

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.

$, $elemMatch, $slice, $meta

The operators of MongoDBs projection are not supported.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    253
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    253
  • 1.0.0
    0

Package Sidebar

Install

npm i mongo-project

Weekly Downloads

253

Version

1.0.1

License

MIT

Last publish

Collaborators

  • patrickd-
  • mogbert
  • schlagbauer