Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongodb-language-model

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-language-model

Parses MongoDB query language and creates hierarchical Ampersand.js models

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4K
increased by6.69%
Maintainers
1
Weekly downloads
 
Created
Source

mongodb-language-model

build status

Parses a MongoDB query and creates hierarchical Ampersand.js models for each of the language components, which can then be interacted with programmatically.

UML diagram

This is the hierarchical model that is created when a query is parsed:

Example

var Query = require('mongodb-language-model').Query;
var assert = require('assert');

// you need to specify `{parse: true}` if a raw javascript object is provided
var query = new Query(
    {"foo": 12345, "$and": [ {bar: false}, {baz: "hello"} ] }, 
    {parse: true}
);

// two top-level clauses
assert.equal(query.clauses.length, 2);

// access leaf clause
var leafClause = query.clauses.get('foo');
assert.equal(leafClause.className, 'LeafClause');

// LeafClause provides access to key and value objects. To access the their 
// native values, they need to be serialized.
assert.equal(leafClause.key.serialize(), 'foo');
assert.equal(leafClause.value.serialize(), 12345);

// access the $and expression tree
var exprTree = query.clauses.get('$and');
assert.equal(exprTree.className, 'ExpressionTree');

// get the list of clause keys
var keys = exprTree.expressions.map(function (expr) {
    return expr.clauses.at(0).key.serialize();
});
assert.deepEqual(keys, ['bar', 'baz']);

// get the list of clause values
var values = exprTree.expressions.map(function (expr) {
    return expr.clauses.at(0).value.serialize();
})
assert.deepEqual(values, [false, 'hello']);

Installation

// @todo
npm install --save mongodb-language-model

Testing

npm test

License

Apache 2.0

Keywords

FAQs

Package last updated on 24 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc