MongoDB Database Model

raw JSON →
2.35.0 verified Sat Apr 25 auth: no javascript

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.

error TypeError: model.collections is not a function
cause collections is an array property, not a method.
fix
Access model.collections directly (array), not model.collections()
error Cannot find module 'mongodb-database-model'
cause Missing installation.
fix
Run 'npm install mongodb-database-model'
gotcha The package is designed for internal use in MongoDB Compass; not recommended for external applications.
fix Consider using the official MongoDB Node.js driver or mongoose for general-purpose database modeling.
deprecated Deprecated exports like 'DatabaseModel' may be removed in future versions.
fix Use 'Model' or 'createModel' instead.
npm install mongodb-database-model
yarn add mongodb-database-model
pnpm add mongodb-database-model

Shows how to import and use the createModel factory to instantiate a DatabaseModel object with collections.

import { createModel } from 'mongodb-database-model';

// Create a model from a database info object
const dbModel = createModel({
  _id: 'mydb',
  name: 'mydb',
  collections: ['users', 'orders'],
  collection_count: 2,
});

console.log(dbModel.name); // 'mydb'
console.log(dbModel.collections); // ['users', 'orders']