mongo-query-format

0.1.4 • Public • Published

Software Plumbers Query Formatter for MongoDB

A Query Formatter that allows abstract-query users to create queries properly formatted for MongoDB

Example

let query = Query
    		.from({ a: "23", b: [2,4]})
    		.or({ a: "24", b: [1,16]})
    		.toExpression(Formatter.MONGO);

and query should equal:

{"$or":[
    {"$and":[
        {"a":"23"},
        {"$and":[
            {"b":{"$gte":2}},
            {"b":{"$lt":4}}
        ]}
    ]},
    {"$and":[
        {"a":"24"},
        {"$and":[
            {"b":{"$gte":1}},
            {"b":{"$lt":16}}
        ]}
    ]}
]}

which while a trifle long-winded should be a valid mongo query document.

For the latest API documentation see The Software Plumbers Site

Project Status

Beta. The API is stabilising, and although unit test coverage could be better it seems broadly functional.

Package Sidebar

Install

npm i mongo-query-format

Weekly Downloads

7

Version

0.1.4

License

SEE LICENSE IN LICENSE

Last publish

Collaborators

  • softwareplumber