mongo-mask

1.1.0 • Public • Published

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

/mongo-mask/

    Package Sidebar

    Install

    npm i mongo-mask

    Weekly Downloads

    571

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • tellnes