mongo-explain-match
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

mongo-explain-match

(work in progress)

npm version Build Status

Utility library for explaining why a mongodb document matches a mongodb query.

Example

import { match } from 'mongo-explain-match';

const doc = {
  id: 1
};

const result = match({ id: { $in: [2, 3] } }, doc);

console.log(result);
// {
//   "match": true,
//   "reasons": [
//     {
//       "propertyPath": "id",
//       "queryPath": "id.$in",
//       "type": "IN_SET"
//     }
//   ]
// }

/**
 * can also only provide query to get curried matching function
 */
const docs = [
  { id: 1, name: 'Amanda' },
  { id: 2, name: 'Ben' },
  { id: 3, name: 'Chris' }
];

const filtered = docs.filter(
  match({
    $or: [{ name: /A/ }, { id: 2 }]
  })
);
// filtered === [
//   { id: 1, name: 'Amanda' },
//   { id: 2, name: 'Ben' },
// ];

Implemented query operators

Will Implement

  • [x] $and
  • [ ] $nor
  • [x] $or
  • [x] $not
  • [x] $nin
  • [x] $in
  • [x] $eq
  • [x] $ne
  • [x] $gt
  • [x] $gte
  • [x] $lt
  • [x] $lte
  • [x] $elemMatch
  • [ ] $size
  • [ ] $all
  • [ ] $exists

Won't Implement

Readme

Keywords

none

Package Sidebar

Install

npm i mongo-explain-match

Weekly Downloads

0

Version

0.0.4

License

Apache-2.0

Unpacked Size

41.8 kB

Total Files

21

Last publish

Collaborators

  • bsouthga
  • christian.yang