Mongo Express Query Params
Express.js middleware implementing the API Query Spec, converting the query to something that can be used to look up the resource.
Installing
npm i --save express-query-params
Basic Usage
This middleware can just be plugged into your stack like so:
var express = require('express');
var queryParams = require('express-query-params');
var app = express();
app.use(queryParams());
Inside any downstream middleware, this plugin will create a parsedQuery
object on the request
. See the test to see how it works.
Advanced Usage
The middleware accepts a few options to make your life easier:
app.use(queryParams({
parseNum: parseFloat,
dateFormat: '2014-01-01',
parseDate: function() {},
typeCast: true,
format: 'mongodb'
}));
Formats
So far, this middleware supports mongodb
and sql
as output formats.
In case of mongodb
, the output is a javascript object that can be used to query MongoDb.
In case of sql
, it will output a WHERE
clause for you as a string.
Tests
mocha