Nincompoops Producing Methane
    Have ideas to improve npm?Join in the discussion! »

    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

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

    Won't Implement

    Keywords

    none

    Install

    npm i mongo-explain-match

    DownloadsWeekly Downloads

    1

    Version

    0.0.4

    License

    Apache-2.0

    Unpacked Size

    41.8 kB

    Total Files

    21

    Last publish

    Collaborators

    • avatar
    • avatar