mongo-mask

Convert a json-mask pattern to a mongodb projection

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
mongo-mask
101.1.07 years ago8 years agoMinified + gzip package size for mongo-mask in KB

Readme

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