RauliL / pieru

Creates match functions from MongoDB query objects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pieru 💨

github coveralls npm

MongoDB query compatible object match.

Installation

$ npm install pieru

Usage

import { match } from 'pieru';

const query = {
  name: { $exists: true },
  qty: { $gt: 3 },
  $and: [
    { price: { $lt: 100 } },
    { price: { $gt: 50 } },
  ],
};

match({ name: 'example', qty: 10, price: 65.10 }, query); // -> true
match({ name: 'bla', qty: 10, price: 30.10 }, query);     // -> false

Please check out the query selector section in the MongoDB documentation.

Supported operators

  • All comparison operators
  • All logical operators
  • All element operators except $type
  • All JavaScript operators
  • All array operators

The following operators are currently not supported:

  • All geospatial operators
  • $type operator

The $where operator is supported but disabled by default (security).

const isMatch = match(obj, query, { $where: true });

About

Creates match functions from MongoDB query objects.

License:MIT License


Languages

Language:TypeScript 97.6%Language:JavaScript 2.4%