Registry / database / eslint-plugin-mongodb

eslint-plugin-mongodb

JSON →
library1.0.0jsnpmunverified

ESLint rules for the Node.js MongoDB native driver 2.0 syntax and best practices. Designed to catch common errors and deprecated patterns in MongoDB query calls (find, insert, update, remove). This v1.0.0 release is the first stable version. It provides 8 rules covering argument validation, deprecated method detection, and update operation checks. Integrates as an ESLint plugin using shared settings to customize call patterns via regex. Release cadence is low; no recent updates. Key differentiator: focused specifically on Node driver 2.0 API, unlike generic MongoDB linters.

npm install eslint-plugin-mongodb
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-MONG
E
eslint-plugin-mongodb
databasejavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

rules
import { rules } from 'eslint-plugin-mongodb'
const rules = require('eslint-plugin-mongodb')
Use default export for ESLint config; named export for rules object. The plugin is intended for use as an ESLint plugin, not programmatic import.
default
plugins: ['mongodb']
plugins: ['eslint-plugin-mongodb']
In .eslintrc, the plugin name is 'mongodb', not the full package name.
Rule: no-replace
rules: { 'mongodb/no-replace': 2 }
rules: { 'no-replace': 2 }
All rules must be prefixed with 'mongodb/'.

Example .eslintrc configuration enabling all mongodb plugin rules with default settings.

// Install: npm install --save-dev eslint eslint-plugin-mongodb // .eslintrc.yml plugins: - mongodb rules: mongodb/check-insert-calls: 2 mongodb/check-query-calls: 2 mongodb/check-update-calls: 2 mongodb/check-remove-calls: 2 mongodb/check-deprecated-calls: 2 mongodb/no-replace: 1 mongodb/check-rename-updates: 2 mongodb/check-unset-updates: 2 settings: mongodb: callPatterns: query: - "(\\.|^)db\\.collection\\([^\\)]+\\)\\.(find|findOne|)$" update: - "(\\.|^)db\\.collection\\([^\\)]+\\)\\.(findOneAndUpdate|updateOne|updateMany)$" insert: - "(\\.|^)db\\.collection\\([^\\)]+\\)\\.(insertOne|insertMany)$" remove: - "(\\.|^)db\\.collection\\([^\\)]+\\)\\.(findOneAndDelete|deleteOne|deleteMany)$" deprecated: - "(\\.|^)db\\.collection\\([^\\)]+\\)\\.(remove|update|findAndModify|ensureIndex|findAndRemove|insert|dropAllIndexes)$"
Debug
Known issues
breakingAll rules require prefix 'mongodb/' when configured
fix
Use 'rules: { "mongodb/no-replace": 2 }' instead of 'rules: { "no-replace": 2 }'
affects: >=1.0
gotchaShared settings callPatterns are regex strings; must double-escape backslashes
fix
Use '\\.' for a literal dot instead of '.'
affects: >=1.0
gotchaPlugin does not work with MongoDB driver 3.0+ methods (e.g., collection.bulkWrite)
fix
Customize callPatterns in settings to match driver 3.0 API, or use a different linter
affects: >=1.0
deprecatedDriver 2.0 is deprecated; consider using driver 3.0+
fix
Upgrade to mongodb driver >=3.0 and adjust callPatterns accordingly
affects: >=1.0
Errors
Common errors & fixes
Cannot read property 'collection' of undefined
Rule expects db.collection() pattern but db is not defined in scope
fix
Ensure MongoDB connection object is named 'db' or adjust callPatterns in settings
Parsing error: Unexpected token /
Using regex literal in .eslintrc instead of string pattern
fix
Wrap patterns in quotes: '(\.|^)db\.collection\([^\)]+\)\.(find|findOne|)$'
ESLint configuration is invalid: "rules": ["mongodb/no-replace": 0] is not an array
Using array syntax instead of object syntax in .eslintrc
fix
Use object syntax: 'rules: { "mongodb/no-replace": 0 }'
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
eslint-plugin-mongodb — npm install eslint-plugin-mongodb · libregistry