pieru
v2.1.0
Published
MongoDB query compatible object match
Downloads
96
Readme
pieru 💨
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 });