{"id":25520,"library":"eslint-plugin-mongodb","title":"eslint-plugin-mongodb","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/nfroidure/eslint-plugin-mongodb","tags":["javascript","eslint","eslintplugin","mongodb","query","queries","mongo"],"install":[{"cmd":"npm install eslint-plugin-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Use default export for ESLint config; named export for rules object. The plugin is intended for use as an ESLint plugin, not programmatic import.","wrong":"const rules = require('eslint-plugin-mongodb')","symbol":"rules","correct":"import { rules } from 'eslint-plugin-mongodb'"},{"note":"In .eslintrc, the plugin name is 'mongodb', not the full package name.","wrong":"plugins: ['eslint-plugin-mongodb']","symbol":"default","correct":"plugins: ['mongodb']"},{"note":"All rules must be prefixed with 'mongodb/'.","wrong":"rules: { 'no-replace': 2 }","symbol":"Rule: no-replace","correct":"rules: { 'mongodb/no-replace': 2 }"}],"quickstart":{"code":"// Install: npm install --save-dev eslint eslint-plugin-mongodb\n// .eslintrc.yml\nplugins:\n  - mongodb\nrules:\n  mongodb/check-insert-calls: 2\n  mongodb/check-query-calls: 2\n  mongodb/check-update-calls: 2\n  mongodb/check-remove-calls: 2\n  mongodb/check-deprecated-calls: 2\n  mongodb/no-replace: 1\n  mongodb/check-rename-updates: 2\n  mongodb/check-unset-updates: 2\nsettings:\n  mongodb:\n    callPatterns:\n      query:\n        - \"(\\\\.|^)db\\\\.collection\\\\([^\\\\)]+\\\\)\\\\.(find|findOne|)$\"\n      update:\n        - \"(\\\\.|^)db\\\\.collection\\\\([^\\\\)]+\\\\)\\\\.(findOneAndUpdate|updateOne|updateMany)$\"\n      insert:\n        - \"(\\\\.|^)db\\\\.collection\\\\([^\\\\)]+\\\\)\\\\.(insertOne|insertMany)$\"\n      remove:\n        - \"(\\\\.|^)db\\\\.collection\\\\([^\\\\)]+\\\\)\\\\.(findOneAndDelete|deleteOne|deleteMany)$\"\n      deprecated:\n        - \"(\\\\.|^)db\\\\.collection\\\\([^\\\\)]+\\\\)\\\\.(remove|update|findAndModify|ensureIndex|findAndRemove|insert|dropAllIndexes)$\"","lang":"javascript","description":"Example .eslintrc configuration enabling all mongodb plugin rules with default settings."},"warnings":[{"fix":"Use 'rules: { \"mongodb/no-replace\": 2 }' instead of 'rules: { \"no-replace\": 2 }'","message":"All rules require prefix 'mongodb/' when configured","severity":"breaking","affected_versions":">=1.0"},{"fix":"Use '\\\\.' for a literal dot instead of '.'","message":"Shared settings callPatterns are regex strings; must double-escape backslashes","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Customize callPatterns in settings to match driver 3.0 API, or use a different linter","message":"Plugin does not work with MongoDB driver 3.0+ methods (e.g., collection.bulkWrite)","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Upgrade to mongodb driver >=3.0 and adjust callPatterns accordingly","message":"Driver 2.0 is deprecated; consider using driver 3.0+","severity":"deprecated","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure MongoDB connection object is named 'db' or adjust callPatterns in settings","cause":"Rule expects db.collection() pattern but db is not defined in scope","error":"Cannot read property 'collection' of undefined"},{"fix":"Wrap patterns in quotes: '(\\.|^)db\\.collection\\([^\\)]+\\)\\.(find|findOne|)$'","cause":"Using regex literal in .eslintrc instead of string pattern","error":"Parsing error: Unexpected token /"},{"fix":"Use object syntax: 'rules: { \"mongodb/no-replace\": 0 }'","cause":"Using array syntax instead of object syntax in .eslintrc","error":"ESLint configuration is invalid: \"rules\": [\"mongodb/no-replace\": 0] is not an array"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}