mongodb-mql-engines
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

mongodb-mql-engines

Exposes, on demand, engines used by the MongoDB IntelliJ Plugin for index suggestions.

Example Usage:

const mql = require('mongodb-mql-engines');

const sampleDocuments = [ { a: 1, b: 2 }, { a: 5, b: true } ]

const ns = mql.analyzeNamespace({ database: "mydb", collection: "mycoll" }, sampleDocuments)
const query = mql.parseQuery({ a: 1, b: 2 }, ns)
const index = await mql.suggestIndex([ query ])

console.log(index);

Expected output:

{ index: { a: 1, b: 1 }, coveredQueries: [ { a: 1, b: 2 } ] }

API

analyzeNamespace(namespace: { database: String, collection: String }, sampleDocuments?: Array): Namespace

Creates a new namespace reference with the data distribution calculated from the sample documents. If no sample documents are provided, it won't use this information for suggesting indexes or running any other engine.

The more documents are provided as a sample, the better the index suggestion will be.

mql.parseQuery(query: Json, namespace: Namespace): Query

Parses a JSON query, defined as plain JSON or relaxed EJSON and attaches it to the provided namespace.

mql.suggestIndex(queries: Array): SuggestedIndex

Analyses all the provided queries and returns the best index to cover all of them. In case only a single query is analysed, provide an array with that single query.

Readme

Keywords

none

Package Sidebar

Install

npm i mongodb-mql-engines

Weekly Downloads

8,518

Version

0.0.4

License

Apache-2.0

Unpacked Size

2.11 MB

Total Files

54

Last publish

Collaborators

  • kmruiz