Run MongoDB queries in regular javascript.
(fork of https://github.com/crcn/sift.js)
Why fork https://github.com/crcn/sift.js?
The original project uses recursion and closures to construct a filter function based on the given MongoDB query.
- this makes debugging difficult, as you have to trace through deep function calls with little context of what the original filter was
- this makes it slow when V8 has not optimized it, since recursive and closure-heavy function calls make use of many stacks
- this makes it hard to change a behavior without affecting others
This fork intends to rewrite sift to a compiler like ajv.
- it intends to provide a verbose mode where each leaf comparison can provide a pass/fail status, and/or what the comparison function looks like
- it intends to be tiny and fast
- it intends to be safe, where $where function calls are constrained to the input object
- it intends to stick to the same behavior as MongoDB query operators as possible
Supports node >= 18
npm i @parcellab/sift
-
You need a local copy of MongoDB (e.g. via docker, compose file provided) configured via TEST_MONGODB_URL which defaults to
mongo://localhost:27017/test
-
To update the benchmarks:
- run
npm run test:bench
which will update the human readableoutput.txt
- run
npm run test:bench:csv
- open
output.xlsx
in Microsoft Excel - click on Refresh Data Sources (this imports
output.csv
automatically) - export the updated chart as
output.png
- run