Needle-Pinpointing Machine

    mongodb-query-parser

    2.4.6 • Public • Published

    mongodb-query-parser Check and Test 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

    Keywords

    none

    Install

    npm i mongodb-query-parser

    DownloadsWeekly Downloads

    8,631

    Version

    2.4.6

    License

    Apache-2.0

    Unpacked Size

    33.4 kB

    Total Files

    9

    Last publish

    Collaborators

    • mabaasit
    • alexander_schroll
    • chuck.kalmanek
    • mongodb-js-user
    • rueckstiess
    • durran
    • lerouxb
    • fredtruman
    • mbroadst
    • hswolff
    • satyasinha
    • matt_d_rat
    • rhysm
    • tomhollander
    • alena.khineika
    • jeff-allen-mongo
    • mmarcon
    • jonathan.balsano
    • mongodb-build
    • jack.weir
    • stennie
    • mcasimir
    • kristina.stefano
    • jarjee
    • shaketbaby
    • devtoolsbot
    • addaleax
    • gribnoysup
    • mutukrish
    • imlucas