{"id":45468,"library":"mongodb-pipeline-factory","title":"MongoDB Pipeline Factory","description":"A lightweight TypeScript-first library (v0.23.2, stable) for declaratively generating MongoDB aggregation pipelines. It provides composable helper functions like project, cond, and gt that reduce boilerplate and improve readability over raw pipeline objects. Compared to writing JSON manually, it offers validation, autocompletion, and integration with Node.js and Mongoose. Released under MIT, with 100% test coverage and weekly updates on npm.","status":"active","version":"0.23.2","language":"javascript","source_language":"en","source_url":"https://github.com/ndabAP/mongodb-pipeline-factory","tags":["javascript","mongodb","pipeline","node","mongoose","generator","factory","typescript"],"install":[{"cmd":"npm install mongodb-pipeline-factory","lang":"bash","label":"npm"},{"cmd":"yarn add mongodb-pipeline-factory","lang":"bash","label":"yarn"},{"cmd":"pnpm add mongodb-pipeline-factory","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package; require() is not supported.","wrong":"const cond = require('mongodb-pipeline-factory').cond","symbol":"cond","correct":"import { cond } from 'mongodb-pipeline-factory'"},{"note":"Named export; default export or subpath imports are not available.","wrong":"import project from 'mongodb-pipeline-factory/project'","symbol":"project","correct":"import { project } from 'mongodb-pipeline-factory'"},{"note":"ESM-only; require() will throw. Types are included.","wrong":"const { gt } = require('mongodb-pipeline-factory')","symbol":"gt","correct":"import { gt } from 'mongodb-pipeline-factory'"},{"note":"Named export. Same import pattern as other operators.","wrong":"","symbol":"lt","correct":"import { lt } from 'mongodb-pipeline-factory'"}],"quickstart":{"code":"import { project, cond, gt, sum } from 'mongodb-pipeline-factory';\n\nconst pipeline = project(\n  ['item', 1],\n  ['discount', cond(\n    gt('$qty', 250),\n    30,\n    20\n  )],\n  ['total', { $multiply: ['$price', { $subtract: [1, { $divide: ['$discount', 100] }] }] }]\n);\n\nimport { MongoClient } from 'mongodb';\nconst client = new MongoClient(process.env.MONGODB_URI ?? 'mongodb://localhost:27017');\nawait client.connect();\nconst db = client.db('test');\nconst coll = db.collection('orders');\nconst result = await coll.aggregate(pipeline).toArray();\nconsole.log(result);\nawait client.close();","lang":"typescript","description":"Builds an aggregation pipeline using project, cond, and gt to compute discounts based on quantity, then calculates total price."},"warnings":[{"fix":"Replace `if(condition, trueVal, falseVal)` with `cond(condition, trueVal, falseVal)`.","message":"Deprecated function 'if' will be removed in v1.0. Use 'cond' instead.","severity":"deprecated","affected_versions":">=0.18.0 <1.0.0"},{"fix":"Replace `match(...)` with `filter(...)`.","message":"In v0.20.0, the 'match' function was renamed to 'filter' to avoid conflicts with the MongoDB $match stage.","severity":"breaking","affected_versions":">=0.20.0"},{"fix":"Use spread operator: `const pipeline = [...project(...), ...group(...)]`","message":"Functions like 'project' return plain JavaScript objects, not special pipeline objects. They can be spread into larger pipelines but cannot be passed to require() or treated as constructors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use `gt('$fieldName', value)` not `gt('fieldName', value)`","message":"Operators such as 'gt' and 'lt' accept field path as string with '$' prefix; omitting the '$' will treat it as a literal string, not a field reference.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Replace `addFields(...)` with `add(...)`.","message":"In v0.19.0, the 'addFields' function was removed in favor of 'add' which matches MongoDB's $addFields (stage name unchanged, but function name changed).","severity":"breaking","affected_versions":">=0.19.0"}],"env_vars":null,"search_vec":"'100':57 'aggreg':16 'autocomplet':46 'boilerpl':30 'compar':38 'compos':20 'cond':25 'coverag':59 'declar':13 'factori':3,71 'first':8 'function':22 'generat':14,70 'gt':27 'helper':21 'improv':32 'integr':48 'javascript':65 'json':41 'librari':9 'lightweight':5 'like':23 'manual':42 'mit':55 'mongodb':1,15,66 'mongoos':52,69 'node':68 'node.js':50 'npm':64 'object':37 'offer':44 'pipelin':2,17,36,67 'project':24 'provid':19 'raw':35 'readabl':33 'reduc':29 'releas':53 'stabl':11 'test':58 'typescript':7,72 'typescript-first':6 'updat':62 'v0.23.2':10 'valid':45 'week':61 'write':40","created_at":"2026-06-07T12:55:09.810933+00:00","updated_at":"2026-06-07T12:55:09.810933+00:00","problems":[{"fix":"Change to: `import { cond } from 'mongodb-pipeline-factory'`","cause":"Using CommonJS require() instead of ESM import.","error":"TypeError: _mongodb_pipeline_factory.cond is not a function"},{"fix":"Replace `if` with `cond` in imports and usage.","cause":"The deprecated `if` export was removed; use `cond`.","error":"SyntaxError: The requested module 'mongodb-pipeline-factory' does not provide an export named 'if'"},{"fix":"Ensure the result of factory functions is used directly, not converted to string or JSON manually.","cause":"Using functions like `cond` inside template literals or concatenation, resulting in malformed BSON.","error":"MongoServerError: unknown operator: $cond (... pipeline object not wrapped correctly)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/ndabAP/mongodb-pipeline-factory#readme","github":"https://github.com/ndabAP/mongodb-pipeline-factory","docs":null,"changelog":null,"pypi":null,"npm":"mongodb-pipeline-factory","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}