lite-mongo-query-parser
v1.0.1
Published
A lightweight tool for converting GET request parameters into a clean query for mongoDB
Downloads
4
Readme
Using lite-mongo-query-parser
Converts a request with params (mainly a brunch of values from a single param)
Example:
localhost:4400/API/list?param1=foo,bar¶m2=foo
Query object result:
{ param1: { '$in': [ 'foo', 'bar' ] }, param2: [ 'foo' ] }
CODING
#!javascript
var lmqp = require('lite-mongo-query-parser');
MODEL.find(lmqp(req.query)).exec((err, object) => {
if(!object) {
res.status(404).send({message: 'No object'});
} else {
res.status(200).send({object: object});
}
})