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.
Common errors
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'
Warnings
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.
Install
npm install mongodb-database-model yarn add mongodb-database-model pnpm add mongodb-database-model Imports
- Model
import { Model } from 'mongodb-database-model' - createModel wrong
import createModel from 'mongodb-database-model'correctimport { createModel } from 'mongodb-database-model' - default wrong
const DatabaseModel = require('mongodb-database-model').defaultcorrectimport DatabaseModel from 'mongodb-database-model'
Quickstart
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']