Simplified MongoDB style projection for hiding/showing specific fields.
npm install mongo-project
const project = require('mongo-project');
const object = {
title: 'Bar title',
author: {
name: 'Foo Person',
email: '[email protected]',
},
};
const projectedObject = project(object, {
'author.email': 0,
});
console.dir(projectedObject);
// {
// title: 'Bar title',
// author: {
// name: 'Foo Person'
// }
// }
const project = require('mongo-project');
const object = {
title: 'Bar title',
author: {
name: 'Foo Person',
email: '[email protected]',
},
};
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.
The operators of MongoDBs projection are not supported.