Registry / database / mongo-query-compiler

mongo-query-compiler

JSON →
library1.0.7jsnpmunverified

Converts MongoDB query objects into optimized JavaScript filter functions for in-memory array filtering. Version 1.0.7 is stable with no active development since 2021. Differentiates from lodash's _.filter by supporting MongoDB query operators like $regex, $geoWithin, and $elemMatch. Lightweight, no dependencies, works in browser and Node.js.

npm install mongo-query-compiler
INSTALL
IMPORT
SIG · MONGO-QUERY-COMPIL
M
mongo-query-compiler
databasejavascriptv1.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compileQuery
import compileQuery from 'mongo-query-compiler'
const { compileQuery } = require('mongo-query-compiler')
Default export only. ES module imports require .js extension if using bundlers.
(default)
import compile from 'mongo-query-compiler'
import { compile } from 'mongo-query-compiler'
The default export is named compileQuery, but you can alias it.
MongoQuery
import type { MongoQuery } from 'mongo-query-compiler'
Available as TypeScript type, not a runtime value.

Compiles a MongoDB query into a filter function and applies it to an array.

import compileQuery from 'mongo-query-compiler'; const filter = compileQuery({ age: { $gte: 18 } }); const data = [ { name: 'Alice', age: 25 }, { name: 'Bob', age: 17 } ]; const adults = data.filter(filter); console.log(adults); // [{ name: 'Alice', age: 25 }]
Debug
Known issues
gotchaQuery keys with dots are treated as nested field paths, not literal property names.
fix
Use literal keys with $literal or avoid dots in field names.
affects: >=1.0.0
breakingIn version 1.0.0, the default import changed from compile to compileQuery.
fix
Update imports to use compileQuery as default.
affects: <1.0.0
deprecatedThe $where operator is deprecated in favor of JavaScript function maps.
fix
Use the expression parameter to pass custom functions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Illegal invocation
The compiled function uses this internally but is not bound to an object.
fix
Bind the filter function to the array if needed, or just pass to .filter() directly.
SyntaxError: Unexpected token $
Using a query operator like $regex as a field name directly.
fix
Wrap it in an object: { field: { $regex: 'pattern' } }
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Bingbot
1
Resources
mongo-query-compiler — npm install mongo-query-compiler · libregistry