0.1.0 • Published 9 years ago
jsonapi-mongo-parsers v0.1.0
jsonapi-mongo-parsers
Utilities to parse url parameters for json api query parameters with glue to conviniently hook them up to mongo.
As with json api, it makes no provision for the ?q=
parameter, and instead leaves that choice up
to you.
Install
npm install jsonapi-mongo-parsers
Example
var parseParams = require('jsonapi-mongo-parsers');
var params = {
sort: '-age,+firstName',
fields: '-_id,+email,+firstName',
limit: '10',
offset: '0'
};
var opts = parseParams(params);
collection.find({}, opts, function (err, docs) {
console.dir(docs);
});
The above would yeild this opts
object:
{
sort: {
age: -1,
firstName: 1
},
fields: {
_id: 0,
email: 1,
firstName: 1
},
limit: 10,
offset: 0
}
Parsing a Query
Check out mongo-url-utils for an implementation with a query parser.