mongo-mask
v1.1.0
Published
Convert a json-mask pattern to a mongodb projection
Downloads
4,311
Readme
mongo-mask
mongo-mask
converts a json-mask
pattern to a mongodb projection object which can be used when querying mongodb
for data.
Express example
var mongoMask = require('mongo-mask')
const map =
{ id: '_id' }
app.get('/item', (req, res, next) => {
const fields = req.query.fields ? mongoMask(req.query.fields, { map }) : null
mongoCollection.findOne({}, fields, (err, doc) => {
if (err) return next(err)
doc.id = doc._id
delete doc._id
res.json(doc)
})
})
Install
npm install -S mongo-mask
License
MIT