1.1.0 • Published 7 years ago

mongo-mask v1.1.0

Weekly downloads
81
License
MIT
Repository
github
Last release
7 years ago

mongo-mask

Version npmnpm DownloadsBuild StatusCoverage StatusDependenciesTips

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