@candis/mongo-selector-simplifier

0.1.1 • Public • Published

Mongo Selector Simplifier CircleCI npm

Reduce MongoDB selector query complexity using the commutative, associative and distributive laws by de-separating nested clauses. The output can often times help MongoDB's query planner to chose the best index.

Install

npm install --save @candis/mongo-selector-simplifier

or

yarn add @candis/mongo-selector-simplifier

Usage

import { simplify } from "@candis/mongo-selector-simplifier";

const selector = {
  $and: [
    { name: { $in: ["Rey", "Leia Organa", "Padmé Amidala", "Jyn Erso"] } },
    { name: "Rey" }
  ],
  gender: "Female"
};

const simplifiedSelector = simplify(selector); // outputs { gender: 'Female', 'name': 'Rey' }

Credit

Original work by @gsuess.

License

mongo-selector-simplifier is MIT licensed.

Package Sidebar

Install

npm i @candis/mongo-selector-simplifier

Weekly Downloads

11

Version

0.1.1

License

MIT

Unpacked Size

26 kB

Total Files

11

Last publish

Collaborators

  • larsboehnke
  • cmrhdl
  • hhrayr
  • pritoj_candis