{"id":18572,"library":"monk-middleware-options","title":"Monk Middleware Options","description":"A middleware plugin for Monk (a MongoDB driver) that parses options passed to collection methods. It currently supports the 'safe' option and is intended for use with Monk v7 and earlier. The package is part of the Monk middleware ecosystem and has not been actively developed, with the last release (0.2.1) occurring alongside Monk v4. For modern Monk versions (v7+), option parsing is handled internally or via other middleware such as monk-middleware-cast-ids.","status":"maintenance","version":"0.2.1","language":"javascript","source_language":"en","source_url":"git://github.com/Automattic/monk","tags":["javascript","monk","middleware","options"],"install":[{"cmd":"npm install monk-middleware-options","lang":"bash","label":"npm"},{"cmd":"yarn add monk-middleware-options","lang":"bash","label":"yarn"},{"cmd":"pnpm add monk-middleware-options","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; this middleware is designed to be used with Monk and expects Monk's collection API.","package":"monk","optional":true}],"imports":[{"note":"The package exposes a default export function. CommonJS require works with default exports in this package.","wrong":"const options = require('monk-middleware-options')","symbol":"default","correct":"import options from 'monk-middleware-options'"},{"note":"The package exports a single function as default; destructuring will result in undefined.","wrong":"const { options } = require('monk-middleware-options')","symbol":"options","correct":"const options = require('monk-middleware-options')"},{"note":"This is a default export; named import syntax will not work.","wrong":"import { options } from 'monk-middleware-options'","symbol":"options","correct":"import options from 'monk-middleware-options'"}],"quickstart":{"code":"const monk = require('monk');\nconst options = require('monk-middleware-options');\n\n// Use with Monk's collection middleware\nconst db = monk('localhost/mydb');\nconst users = db.get('users', { castIds: false });\nusers.use(options());\n\n// Now the 'safe' option will be parsed\nusers.insert({ name: 'John' }, { safe: true }).then(doc => {\n  console.log('Inserted:', doc);\n}).catch(err => {\n  console.error(err);\n});","lang":"javascript","description":"Demonstrates basic usage: requiring monk, applying the options middleware to a collection, and using the 'safe' option."},"warnings":[{"fix":"Use writeConcern instead. For Monk v7+, writeConcern is automatically set via connection URI or driver options.","message":"The 'safe' option is deprecated in MongoDB driver 3.0 and later.","severity":"deprecated","affected_versions":">=7.0.0"},{"fix":"Use monk-middleware-cast-ids or handle other options manually.","message":"This middleware only parses the 'safe' option; other options (e.g., writeConcern) are not handled.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Remove usage of this middleware; options are now passed directly to Monk methods.","message":"Monk v6 removed the middleware option parsing mechanism; monk-middleware-options is no longer needed.","severity":"breaking","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Upgrade to Monk v6+ and remove calls to .use(). Options are passed directly to methods.","cause":"Monk v6+ no longer supports .use() for middleware; middleware API was removed.","error":"TypeError: db.get(...).use is not a function"},{"fix":"Use writeConcern instead: { writeConcern: { w: 1 } }.","cause":"The 'safe' option is deprecated and should be replaced with writeConcern.","error":"Error: options.safe is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}