MongoDB query compatible object match.
$ npm install pieru
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.
- 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 });