{"id":27151,"library":"mongodb-database-model","title":"MongoDB Database Model","description":"MongoDB database model class for Compass. Provides a structured representation of a MongoDB database, including collections, indexes, and schema analysis. Version 2.35.0 is the current stable release, part of the MongoDB Compass ecosystem. Built with TypeScript, it offers type-safe database modeling and is used internally by Compass. Infrequently updated, with no known breaking changes in recent versions. Key differentiator: tailored for Compass internal use; not intended for general-purpose MongoDB modeling outside that context.","status":"active","version":"2.35.0","language":"javascript","source_language":"en","source_url":"https://github.com/mongodb-js/compass","tags":["javascript","mongodb-js","typescript"],"install":[{"cmd":"npm install mongodb-database-model","lang":"bash","label":"npm"},{"cmd":"yarn add mongodb-database-model","lang":"bash","label":"yarn"},{"cmd":"pnpm add mongodb-database-model","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Provides the database model class representing a MongoDB database with collections and metadata.","symbol":"Model","correct":"import { Model } from 'mongodb-database-model'"},{"note":"createModel is a named export, not a default export. Use destructured import.","wrong":"import createModel from 'mongodb-database-model'","symbol":"createModel","correct":"import { createModel } from 'mongodb-database-model'"},{"note":"The package has a default export as well. CJS require (e.g., require('mongodb-database-model')) may require .default in Node <14.","wrong":"const DatabaseModel = require('mongodb-database-model').default","symbol":"default","correct":"import DatabaseModel from 'mongodb-database-model'"}],"quickstart":{"code":"import { createModel } from 'mongodb-database-model';\n\n// Create a model from a database info object\nconst dbModel = createModel({\n  _id: 'mydb',\n  name: 'mydb',\n  collections: ['users', 'orders'],\n  collection_count: 2,\n});\n\nconsole.log(dbModel.name); // 'mydb'\nconsole.log(dbModel.collections); // ['users', 'orders']\n","lang":"typescript","description":"Shows how to import and use the createModel factory to instantiate a DatabaseModel object with collections."},"warnings":[{"fix":"Consider using the official MongoDB Node.js driver or mongoose for general-purpose database modeling.","message":"The package is designed for internal use in MongoDB Compass; not recommended for external applications.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use 'Model' or 'createModel' instead.","message":"Deprecated exports like 'DatabaseModel' may be removed in future versions.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Access model.collections directly (array), not model.collections()","cause":"collections is an array property, not a method.","error":"TypeError: model.collections is not a function"},{"fix":"Run 'npm install mongodb-database-model'","cause":"Missing installation.","error":"Cannot find module 'mongodb-database-model'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}