Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including lite-mongo-query-parser with all npm packages installed. Try it out:

var liteMongoQueryParser = require("lite-mongo-query-parser")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

lite-mongo-query-parser v1.0.1

A lightweight tool for converting GET request parameters into a clean query for mongoDB

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&param2=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}); 
    }
})

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free