mongodb-querystring
Pass MongoDB query through URL query string.
Last updated 5 years ago by touv .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mongodb-querystring 
SYNC missed versions from official npm registry.

MongoDB query through URL

Pass MongoDB query through URL query string.

Contributors

Installation

With npm do:

$ npm install mongodb-querystring

Tests

Use mocha to run the tests.

$ npm install mocha
$ mocha test

API Documentation

stringify(input : Object, [separator : String]) : String

Converts query to a URL query string.

	var mqs = require('mongodb-querystring');
	var qry = {
     "$query" : {
       "age" : {
         "$gte" : new Date(1976, 11, 14)
       },
       "$or": [
         { "cuisine": "Italian" },
         { "address.zipcode": "10075" }
       ]
     },
     "$limit" : 20,
     "$orderby" : {
       "age" : -1,
       "posts": 1
     }
   };
   console.log(mqs.stringify(qry);

Output:

'$query[age][$gte]=219366000000^D&$query[$or][0][cuisine]=Italian&$query[$or][1][address.zipcode]=10075&$limit=20^N&$orderby[age]=-1^N&$orderby[posts]=1^N'

parse(input : String) : Object

parse(input : Object) : Object

Parse input to convert to an query.

	var mqs = require('mongodb-querystring');
	var qry = '$query[type][$in][0]=food&$query[type][$in][1]=snacks';
	console.dir(mqs.parse(qry));

Output:

{ '$query': { type: { '$in': [ 'food', 'snacks' ] } } }

create(input : String) : Object

create(input : Object) : Object

Parse input to convert to an Object query.

	var mqs = require('mongodb-querystring');
	var qry = mqs.create(req.query);
	console.log(qry.$query());
	console.log(qry.$limit(10));

Also

Current Tags

  • 1.0.3                                ...           latest (5 years ago)

4 Versions

  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (1)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |