Registry / database / monk-middleware-fields

monk-middleware-fields

JSON →
library0.2.0jsnpmunverified

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.

npm install monk-middleware-fields
INSTALL
IMPORT
SIG · MONK-MIDDLEWARE-FI
M
monk-middleware-fields
databasejavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fields
import fields from 'monk-middleware-fields'
const { fields } = require('monk-middleware-fields')
Package has a default export.
fields
const fields = require('monk-middleware-fields')
const fields = require('monk-middleware-fields').default
In CommonJS, just require the module; no .default needed.
Monk
import monk from 'monk'
import { Monk } from 'monk'
Monk uses default export.

Shows how to apply the fields middleware to a Monk collection and use field filtering in queries.

import monk from 'monk'; import fields from 'monk-middleware-fields'; const db = monk('localhost/mydb'); const users = db.get('users', { middlewares: [fields()] }); // Insert a user await users.insert({ name: 'John', email: 'john@example.com', age: 30 }); // Query with fields: only name and email const result = await users.findOne({}, { fields: { name: 1, email: 1 } }); console.log(result); // { _id: ..., name: 'John', email: 'john@example.com' } // Or exclude fields const result2 = await users.findOne({}, { fields: { age: 0 } }); console.log(result2); // { _id: ..., name: 'John', email: 'john@example.com' }
Debug
Known issues
deprecatedPackage is no longer actively maintained; last release 0.2.0 in 2016.
fix
Consider using built-in MongoDB projection in Monk directly or find an alternative.
affects: all
gotchaThe fields option in queries may not work as expected if not passed to the middleware.
fix
Ensure you instantiate the collection with the middleware: db.get('collection', { middlewares: [fields()] }).
affects: all
gotchaThe fields middleware does not support nested field paths like 'address.city' in some versions.
fix
Upgrade to 0.2.0 or use dot notation manually.
affects: <0.2.0
breakingMonk 7.0.0 changed internal MongoDB driver; monk-middleware-fields may not be fully compatible.
fix
Test with your Monk version; consider using Monk's built-in projection.
affects: monk >=7.0.0
Errors
Common errors & fixes
TypeError: fields is not a function
Using named import instead of default import in ESM.
fix
Use 'import fields from 'monk-middleware-fields'' instead of 'import { fields } from 'monk-middleware-fields''.
Error: Cannot find module 'monk-middleware-fields'
Package not installed or not in node_modules.
fix
Run 'npm install monk-middleware-fields'.
fields option ignored in query results
Middleware not applied to the collection instance.
fix
Pass { middlewares: [fields()] } when creating the collection.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
monkrequiredProvides the database instance and middleware system
Agent activity
4 hits · last 30 days
node
4
Resources
monk-middleware-fields — npm install monk-middleware-fields · libregistry