{"id":42523,"library":"codemirror-mongodb","title":"codemirror-mongodb","description":"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.","status":"active","version":"0.10.3","language":"javascript","source_language":"en","source_url":"git://github.com/mongodb-js/codemirror-mongodb","tags":["javascript"],"install":[{"cmd":"npm install codemirror-mongodb","lang":"bash","label":"npm"},{"cmd":"yarn add codemirror-mongodb","lang":"bash","label":"yarn"},{"cmd":"pnpm add codemirror-mongodb","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core editor dependency; only compatible with CodeMirror v5 (not v6).","package":"codemirror","optional":false},{"reason":"Required for React integration examples.","package":"react-codemirror","optional":true}],"imports":[{"note":"Package registers a CodeMirror hint addon; no exports. Must be required after CodeMirror itself. ESM not supported.","wrong":"import 'codemirror-mongodb'","symbol":"","correct":"require('codemirror-mongodb/addon/hint/mongodb-hint')"},{"note":"codemirror-mongodb is a side-effect module that modifies CodeMirror; it does not export anything.","wrong":"const CodeMirror = require('codemirror-mongodb')","symbol":"","correct":"const CodeMirror = require('codemirror'); require('codemirror-mongodb/addon/hint/mongodb-hint')"},{"note":"Importing the main package does nothing; must import the specific addon path.","wrong":"require('codemirror-mongodb')","symbol":"","correct":"require('codemirror-mongodb/addon/hint/mongodb-hint')"}],"quickstart":{"code":"const CodeMirror = require('codemirror');\nrequire('codemirror/addon/hint/show-hint');\nrequire('codemirror/addon/edit/closebrackets');\nrequire('codemirror/addon/edit/matchbrackets');\nrequire('codemirror/addon/selection/active-line');\nrequire('codemirror-mongodb/addon/hint/mongodb-hint');\n\nconst editor = CodeMirror.fromTextArea(document.getElementById('editor'), {\n  mode: 'javascript',\n  theme: 'mongodb',\n  lineNumbers: false,\n  scrollbarStyle: 'null',\n  autoCloseBrackets: true,\n  matchBrackets: true,\n  extraKeys: {\n    'Ctrl-Space': 'autocomplete',\n    'Shift-Enter': 'parse'\n  },\n  mongodb: {\n    fields: {\n      _id: 'ObjectId',\n      name: 'String',\n      age: 'Number',\n      number_of_pets: 'Number',\n      addresses: 'Array',\n      'addresses.street': 'String'\n    }\n  }\n});\n\neditor.on('beforeChange', (cm, change) => {\n  if (change.update) {\n    const newtext = change.text.join('').replace(/\\n/g, '');\n    change.update(change.from, change.to, [newtext]);\n  }\n  return true;\n});\n","lang":"javascript","description":"Sets up a CodeMirror editor with MongoDB autocompletion based on a schema of fields, and enforces single-line input."},"warnings":[{"fix":"Use codemirror6 and find alternative MongoDB hint addon or implement custom.","message":"Package is not compatible with CodeMirror v6; requires CodeMirror v5.","severity":"deprecated","affected_versions":"all"},{"fix":"Require 'codemirror-mongodb/addon/hint/mongodb-hint' instead of 'codemirror-mongodb'.","message":"Importing 'codemirror-mongodb' without the full path to the addon does nothing; hints will not register.","severity":"gotcha","affected_versions":"all"},{"fix":"Do not assign the require to a variable; just require it alongside CodeMirror.","message":"The package does not export anything; it must be required for side-effects only.","severity":"gotcha","affected_versions":"all"},{"fix":"Include a 'mongodb' object with a 'fields' property in CodeMirror options.","message":"The 'mongodb' option must be passed in the editor configuration to enable field autocompletion.","severity":"gotcha","affected_versions":"all"},{"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.","message":"The 'theme: mongodb' requires loading the CodeMirror MongDB theme CSS separately.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.10.3':23 '2021':27 'activ':68 'add':7 'autocomplet':8 'awar':43 'cadenc':31 'codemirror':2,4,35,66,73 'codemirror-mongodb':1 'commonj':59 'complet':44 'context':42 'context-awar':41 'develop':69 'differenti':32 'e.g':45 'editor':56 'extens':5 'field':11,21,46 'hint':37 'includ':51 'integr':33 'javascript':75 'last':24 'leverag':16 'low':29 'mongodb':3,10,54 'mongodb-them':53 'name':12,47 'pattern':15 'provid':19,40 'queri':14 'quotes/regex':49 'react':62,65 'react-codemirror':64 'recent':70 'releas':30 'reli':71 'requir':60 'schema':20 'support':58 'system':38 'theme':55,57 'type':48 'updat':25 'user':18 'user-provid':17 'v5':74 'version':22 'via':63","created_at":"2026-06-05T16:55:23.762557+00:00","updated_at":"2026-06-05T16:55:23.762557+00:00","problems":[{"fix":"Use require('codemirror-mongodb/addon/hint/mongodb-hint')","cause":"Importing the main package instead of the addon path.","error":"Cannot find module 'codemirror-mongodb'"},{"fix":"Add 'mongodb: { fields: { ... } }' to the editor options.","cause":"Missing 'mongodb' option in CodeMirror configuration.","error":"Uncaught TypeError: Cannot read properties of undefined (reading 'fields')"},{"fix":"Ensure require('codemirror/addon/hint/show-hint') is called before mongodb-hint.","cause":"show-hint addon not loaded before using mongodb-hint.","error":"Expected a function but got undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"http://github.com/mongodb-js/codemirror-mongodb","github":"git://github.com/mongodb-js/codemirror-mongodb","docs":null,"changelog":null,"pypi":null,"npm":"codemirror-mongodb","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}