Skip to content

CandisIO/mongo-selector-simplifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published