{"id":18570,"library":"monk-middleware-fields","title":"monk-middleware-fields","description":"A middleware for the Monk MongoDB library that parses and filters document fields. Version 0.2.0 is the latest stable release. This package is part of the Monk middleware ecosystem and extracts the field selection logic into a separate module, allowing reusable field filtering in queries and updates. Unlike manual field projection, monk-middleware-fields provides a declarative way to include or exclude fields consistently across operations. It is designed to work with Monk versions that support middleware (v5+). No active development observed; project appears unmaintained.","status":"maintenance","version":"0.2.0","language":"javascript","source_language":"en","source_url":"git://github.com/Automattic/monk","tags":["javascript","monk","middleware","fields"],"install":[{"cmd":"npm install monk-middleware-fields","lang":"bash","label":"npm"},{"cmd":"yarn add monk-middleware-fields","lang":"bash","label":"yarn"},{"cmd":"pnpm add monk-middleware-fields","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the database instance and middleware system","package":"monk","optional":false}],"imports":[{"note":"Package has a default export.","wrong":"const { fields } = require('monk-middleware-fields')","symbol":"fields","correct":"import fields from 'monk-middleware-fields'"},{"note":"In CommonJS, just require the module; no .default needed.","wrong":"const fields = require('monk-middleware-fields').default","symbol":"fields","correct":"const fields = require('monk-middleware-fields')"},{"note":"Monk uses default export.","wrong":"import { Monk } from 'monk'","symbol":"Monk","correct":"import monk from 'monk'"}],"quickstart":{"code":"import monk from 'monk';\nimport fields from 'monk-middleware-fields';\n\nconst db = monk('localhost/mydb');\nconst users = db.get('users', { middlewares: [fields()] });\n\n// Insert a user\nawait users.insert({ name: 'John', email: 'john@example.com', age: 30 });\n\n// Query with fields: only name and email\nconst result = await users.findOne({}, { fields: { name: 1, email: 1 } });\nconsole.log(result); // { _id: ..., name: 'John', email: 'john@example.com' }\n\n// Or exclude fields\nconst result2 = await users.findOne({}, { fields: { age: 0 } });\nconsole.log(result2); // { _id: ..., name: 'John', email: 'john@example.com' }\n","lang":"typescript","description":"Shows how to apply the fields middleware to a Monk collection and use field filtering in queries."},"warnings":[{"fix":"Consider using built-in MongoDB projection in Monk directly or find an alternative.","message":"Package is no longer actively maintained; last release 0.2.0 in 2016.","severity":"deprecated","affected_versions":"all"},{"fix":"Ensure you instantiate the collection with the middleware: db.get('collection', { middlewares: [fields()] }).","message":"The fields option in queries may not work as expected if not passed to the middleware.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to 0.2.0 or use dot notation manually.","message":"The fields middleware does not support nested field paths like 'address.city' in some versions.","severity":"gotcha","affected_versions":"<0.2.0"},{"fix":"Test with your Monk version; consider using Monk's built-in projection.","message":"Monk 7.0.0 changed internal MongoDB driver; monk-middleware-fields may not be fully compatible.","severity":"breaking","affected_versions":"monk >=7.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use 'import fields from 'monk-middleware-fields'' instead of 'import { fields } from 'monk-middleware-fields''.","cause":"Using named import instead of default import in ESM.","error":"TypeError: fields is not a function"},{"fix":"Run 'npm install monk-middleware-fields'.","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'monk-middleware-fields'"},{"fix":"Pass { middlewares: [fields()] } when creating the collection.","cause":"Middleware not applied to the collection instance.","error":"fields option ignored in query results"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}