mongodb-query-parser
Parse MongoDB queries
Last updated 2 months ago by mcasimir .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mongodb-query-parser 
SYNC missed versions from official npm registry.

mongodb-query-parser travis npm

Safe parsing and validation for MongoDB queries (filters), projections, and more.

Example

Turn some JS code as a string into a real JS object safely and with no bson type loss:

require('mongodb-query-parser')('{_id: ObjectId("58c33a794d08b991e3648fd2")}');
// >>> {_id: ObjectId('58c33a794d08b991e3648fd2'x)}

Usage with codemirror

var parser = require('mongodb-query-parser');
var query = '{_id: ObjectId("58c33a794d08b991e3648fd2")}';
// What is this highlighting/language mode for this string?
parser.detect(query);
// >>> `javascript`

var queryAsJSON = '{"_id":{"$oid":"58c33a794d08b991e3648fd2"}}';
// What is this highlighting/language mode for this string?
parser.detect(queryAsJSON);
// >>> `json`

// Turn it into a JS string that looks pretty in codemirror:
parser.toJavascriptString(parse(query));
// >>> '{_id:ObjectId(\'58c33a794d08b991e3648fd2\')}'

Extended JSON Support

var parser = require('mongodb-query-parser');
var EJSON = require('mongodb-extended-json');
var queryAsAnObjectWithTypes = parser.parseFilter(query);

// Use extended json to prove types are intact
EJSON.stringify(queryAsAnObjectWithTypes);
// >>> '{"_id":{"$oid":"58c33a794d08b991e3648fd2"}}'

var queryAsJSON = '{"_id":{"$oid":"58c33a794d08b991e3648fd2"}}';
parser.detect(queryAsJSON);
// >>> `json`

Migrations

We aim to not have any API breaking changes in this library as we consider it stable, but breakages may occur whenever we upgrade a core dependency or perform a major refactor.

We have a migration guide which covers what to look out for between releases.

Related

License

Apache 2.0

Current Tags

  • 2.1.2                                ...           latest (2 months ago)

50 Versions

  • 2.1.2                                ...           2 months ago
  • 2.1.1                                ...           7 months ago
  • 2.1.0                                ...           7 months ago
  • 2.0.2                                ...           9 months ago
  • 2.0.1                                ...           9 months ago
  • 2.0.0                                ...           9 months ago
  • 1.6.0-rc.0                                ...           9 months ago
  • 1.5.0 [deprecated]           ...           9 months ago
  • 1.4.3 [deprecated]           ...           a year ago
  • 1.4.2 [deprecated]           ...           a year ago
  • 1.4.1 [deprecated]           ...           a year ago
  • 1.4.0 [deprecated]           ...           a year ago
  • 1.3.6 [deprecated]           ...           a year ago
  • 1.3.5 [deprecated]           ...           a year ago
  • 1.3.4 [deprecated]           ...           2 years ago
  • 1.3.3 [deprecated]           ...           2 years ago
  • 1.3.2 [deprecated]           ...           2 years ago
  • 1.3.1 [deprecated]           ...           2 years ago
  • 1.3.0 [deprecated]           ...           2 years ago
  • 1.2.5 [deprecated]           ...           2 years ago
  • 1.2.4 [deprecated]           ...           2 years ago
  • 1.2.3 [deprecated]           ...           2 years ago
  • 1.2.2 [deprecated]           ...           2 years ago
  • 1.2.1 [deprecated]           ...           2 years ago
  • 1.1.3 [deprecated]           ...           2 years ago
  • 1.1.2 [deprecated]           ...           2 years ago
  • 1.1.1 [deprecated]           ...           2 years ago
  • 1.1.0 [deprecated]           ...           2 years ago
  • 1.0.2 [deprecated]           ...           3 years ago
  • 1.0.1 [deprecated]           ...           3 years ago
  • 1.0.0 [deprecated]           ...           3 years ago
  • 0.7.1 [deprecated]           ...           3 years ago
  • 0.7.0 [deprecated]           ...           3 years ago
  • 0.6.1 [deprecated]           ...           3 years ago
  • 0.6.0 [deprecated]           ...           3 years ago
  • 0.5.1 [deprecated]           ...           3 years ago
  • 0.5.0 [deprecated]           ...           3 years ago
  • 0.4.0 [deprecated]           ...           3 years ago
  • 0.3.1 [deprecated]           ...           3 years ago
  • 0.3.0 [deprecated]           ...           3 years ago
  • 0.2.2 [deprecated]           ...           3 years ago
  • 0.2.1 [deprecated]           ...           3 years ago
  • 0.2.0 [deprecated]           ...           3 years ago
  • 0.1.5 [deprecated]           ...           3 years ago
  • 0.1.4 [deprecated]           ...           3 years ago
  • 0.1.3 [deprecated]           ...           3 years ago
  • 0.1.2 [deprecated]           ...           3 years ago
  • 0.1.1 [deprecated]           ...           3 years ago
  • 0.1.0 [deprecated]           ...           3 years ago
  • 0.0.1 [deprecated]           ...           3 years ago

Copyright 2014 - 2017 © taobao.org |