(work in progress)
Utility library for explaining why a mongodb document matches a mongodb query.
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' },
// ];-
$and -
$nor -
$or -
$not -
$nin -
$in -
$eq -
$ne -
$gt -
$gte -
$lt -
$lte -
$elemMatch -
$size -
$all -
$exists
-
$type -
$regex(No support -- would require Perl compatible regular expressions, can use{ field: /pattern/}syntax instead)