Registry / database / codemirror-mongodb

codemirror-mongodb

JSON →
library0.10.3jsnpmunverified

CodeMirror extension that adds autocompletion for MongoDB field names and query patterns, leveraging user-provided schema fields. Version 0.10.3, last updated in 2021, with low release cadence. Differentiators: integrates with CodeMirror's hint system to provide context-aware completions (e.g., field names, typed quotes/regex), and includes a MongoDB-themed editor theme. Supports CommonJS require and React via react-codemirror. No active development recently; relies on CodeMirror v5.

npm install codemirror-mongodb
INSTALL
IMPORT
SIG · CODEMIRROR-MONGODB
C
codemirror-mongodb
databasejavascriptv0.10.3
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.

require('codemirror-mongodb/addon/hint/mongodb-hint')
import 'codemirror-mongodb'
Package registers a CodeMirror hint addon; no exports. Must be required after CodeMirror itself. ESM not supported.
const CodeMirror = require('codemirror'); require('codemirror-mongodb/addon/hint/mongodb-hint')
const CodeMirror = require('codemirror-mongodb')
codemirror-mongodb is a side-effect module that modifies CodeMirror; it does not export anything.
require('codemirror-mongodb/addon/hint/mongodb-hint')
require('codemirror-mongodb')
Importing the main package does nothing; must import the specific addon path.

Sets up a CodeMirror editor with MongoDB autocompletion based on a schema of fields, and enforces single-line input.

const CodeMirror = require('codemirror'); require('codemirror/addon/hint/show-hint'); require('codemirror/addon/edit/closebrackets'); require('codemirror/addon/edit/matchbrackets'); require('codemirror/addon/selection/active-line'); require('codemirror-mongodb/addon/hint/mongodb-hint'); const editor = CodeMirror.fromTextArea(document.getElementById('editor'), { mode: 'javascript', theme: 'mongodb', lineNumbers: false, scrollbarStyle: 'null', autoCloseBrackets: true, matchBrackets: true, extraKeys: { 'Ctrl-Space': 'autocomplete', 'Shift-Enter': 'parse' }, mongodb: { fields: { _id: 'ObjectId', name: 'String', age: 'Number', number_of_pets: 'Number', addresses: 'Array', 'addresses.street': 'String' } } }); editor.on('beforeChange', (cm, change) => { if (change.update) { const newtext = change.text.join('').replace(/\n/g, ''); change.update(change.from, change.to, [newtext]); } return true; });
Debug
Known issues
deprecatedPackage is not compatible with CodeMirror v6; requires CodeMirror v5.
fix
Use codemirror6 and find alternative MongoDB hint addon or implement custom.
affects: all
gotchaImporting 'codemirror-mongodb' without the full path to the addon does nothing; hints will not register.
fix
Require 'codemirror-mongodb/addon/hint/mongodb-hint' instead of 'codemirror-mongodb'.
affects: all
gotchaThe package does not export anything; it must be required for side-effects only.
fix
Do not assign the require to a variable; just require it alongside CodeMirror.
affects: all
gotchaThe 'mongodb' option must be passed in the editor configuration to enable field autocompletion.
fix
Include a 'mongodb' object with a 'fields' property in CodeMirror options.
affects: all
gotchaThe 'theme: mongodb' requires loading the CodeMirror MongDB theme CSS separately.
fix
Add '@import url(https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.0/theme/monokai.min.css);' or include the mongodb CSS file from the package.
affects: all
Errors
Common errors & fixes
Cannot find module 'codemirror-mongodb'
Importing the main package instead of the addon path.
fix
Use require('codemirror-mongodb/addon/hint/mongodb-hint')
Uncaught TypeError: Cannot read properties of undefined (reading 'fields')
Missing 'mongodb' option in CodeMirror configuration.
fix
Add 'mongodb: { fields: { ... } }' to the editor options.
Expected a function but got undefined
show-hint addon not loaded before using mongodb-hint.
fix
Ensure require('codemirror/addon/hint/show-hint') is called before mongodb-hint.
Upgrade
Version history
0.10.3latest on npm
Audit
Dependencies
codemirrorrequiredCore editor dependency; only compatible with CodeMirror v5 (not v6).
react-codemirroroptionalRequired for React integration examples.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
codemirror-mongodb — npm install codemirror-mongodb · libregistry