{"id":25955,"library":"mongo-query-compiler","title":"mongo-query-compiler","description":"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.","status":"active","version":"1.0.7","language":"javascript","source_language":"en","source_url":"https://github.com/aptivator/mongo-query-compiler","tags":["javascript","mongo","mongodb","query","array","filtering","transpiler","compiler"],"install":[{"cmd":"npm install mongo-query-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add mongo-query-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add mongo-query-compiler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export only. ES module imports require .js extension if using bundlers.","wrong":"const { compileQuery } = require('mongo-query-compiler')","symbol":"compileQuery","correct":"import compileQuery from 'mongo-query-compiler'"},{"note":"The default export is named compileQuery, but you can alias it.","wrong":"import { compile } from 'mongo-query-compiler'","symbol":"(default)","correct":"import compile from 'mongo-query-compiler'"},{"note":"Available as TypeScript type, not a runtime value.","wrong":"","symbol":"MongoQuery","correct":"import type { MongoQuery } from 'mongo-query-compiler'"}],"quickstart":{"code":"import compileQuery from 'mongo-query-compiler';\nconst filter = compileQuery({ age: { $gte: 18 } });\nconst data = [\n  { name: 'Alice', age: 25 },\n  { name: 'Bob', age: 17 }\n];\nconst adults = data.filter(filter);\nconsole.log(adults); // [{ name: 'Alice', age: 25 }]","lang":"javascript","description":"Compiles a MongoDB query into a filter function and applies it to an array."},"warnings":[{"fix":"Use literal keys with $literal or avoid dots in field names.","message":"Query keys with dots are treated as nested field paths, not literal property names.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update imports to use compileQuery as default.","message":"In version 1.0.0, the default import changed from compile to compileQuery.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use the expression parameter to pass custom functions.","message":"The $where operator is deprecated in favor of JavaScript function maps.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Bind the filter function to the array if needed, or just pass to .filter() directly.","cause":"The compiled function uses this internally but is not bound to an object.","error":"TypeError: Illegal invocation"},{"fix":"Wrap it in an object: { field: { $regex: 'pattern' } }","cause":"Using a query operator like $regex as a field name directly.","error":"SyntaxError: Unexpected token $"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}