{"id":18573,"library":"monk-middleware-query","title":"Monk Middleware Query","description":"monk-middleware-query is a middleware for the Monk MongoDB library (version 0.2.0) that parses and transforms query objects. It allows you to define query processing logic that runs before database operations, such as modifying or validating query conditions. This package is part of the Monk ecosystem and is intended to be used with Monk's middleware pipeline. It is stable but minimally documented, with no recent updates. Key differentiator: it provides a structured way to intercept and manipulate queries in Monk applications.","status":"maintenance","version":"0.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/Automattic/monk","tags":["javascript","monk","middleware","query"],"install":[{"cmd":"npm install monk-middleware-query","lang":"bash","label":"npm"},{"cmd":"yarn add monk-middleware-query","lang":"bash","label":"yarn"},{"cmd":"pnpm add monk-middleware-query","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"monk-middleware-query is a middleware plugin for Monk and requires Monk to function.","package":"monk","optional":false}],"imports":[{"note":"The module exports a function as the default export. Use default import for ESM. CommonJS users should use require('monk-middleware-query').default or import * as q from 'monk-middleware-query'.","wrong":"const { query } = require('monk-middleware-query')","symbol":"default","correct":"import query from 'monk-middleware-query'"},{"note":"There is no named export; the entire module is a single function. Attempting a named import will result in undefined.","wrong":"import { query } from 'monk-middleware-query'","symbol":"Middleware","correct":"import query from 'monk-middleware-query'"},{"note":"The middleware must be required/imported and called as a function (optionally with options) before being used with .use(). Passing the string will not work.","wrong":"db.use('monk-middleware-query')","symbol":"monk instance .use","correct":"db.use(require('monk-middleware-query')())"}],"quickstart":{"code":"import monk from 'monk';\nimport queryMiddleware from 'monk-middleware-query';\n\nconst db = monk('localhost/mydb');\ndb.use(queryMiddleware());\n\nconst users = db.get('users');\n// With middleware, you can transform queries: for example, enforce a filter\n// The middleware processes the query before it reaches the database.\nconst docs = await users.find({ age: { $gt: 20 } });\nconsole.log(docs);\n","lang":"javascript","description":"Demonstrates how to import and apply the query middleware to a Monk database instance."},"warnings":[{"fix":"Use db.use(queryMiddleware()) instead of db.use(queryMiddleware).","message":"The middleware must be called as a function (e.g., queryMiddleware()) before passing to .use(), not just passed as a reference.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider using Monk's built-in middleware or another middleware package compatible with your Monk version.","message":"This package is deprecated or not actively maintained. It may not work with newer versions of Monk (>=7.0.0) due to breaking changes in Monk's middleware API.","severity":"gotcha","affected_versions":">=7.0.0"},{"fix":"Refer to the GitHub source for usage details.","message":"The package has no README or documentation. Understanding its behavior requires reading the source code.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure db is a Monk database instance (e.g., const db = monk('uri')) before calling db.use().","cause":"Using the middleware before initializing the Monk database connection.","error":"TypeError: db.use is not a function"},{"fix":"Run npm install monk-middleware-query and verify the import statement.","cause":"The package is not installed or the import path is incorrect.","error":"Cannot find module 'monk-middleware-query'"},{"fix":"Use db.use(queryMiddleware()) instead of db.use(queryMiddleware).","cause":"Passing the middleware module directly instead of calling it as a function.","error":"Middleware must be a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}