mongo-project
Simplified MongoDB style projection for hiding/showing specific fields.
npm install mongo-project
Usage
Hide some fields from an object
const project = ; const object = title: 'Bar title' author: name: 'Foo Person' email: 'foo.person@example.com' ; const projectedObject = ; consoledirprojectedObject;// {// title: 'Bar title',// author: {// name: 'Foo Person'// }// }
Only show specific fields of an object
const project = ; const object = title: 'Bar title' author: name: 'Foo Person' email: 'foo.person@example.com' ; const projectedObject = ; consoledirprojectedObject;// {// title: 'Bar title',// author: {// name: 'Foo Person'// }// }
tests.
More complex examples can be found in the$, $elemMatch, $slice, $meta
The operators of MongoDBs projection are not supported.