Registry / database / mongodb-collection-model

mongodb-collection-model

JSON →
library5.35.0jsnpmunverified

A data model for MongoDB collection metadata used in the MongoDB Compass ecosystem. Version 5.35.0 provides TypeScript types and supports both ESM and CJS. It models collection properties like indexes, document count, storage size, and validation schema, and is primarily used to represent collection information retrieved from MongoDB servers. Released as part of the mongodb-js Compass packages, it follows the Compass release cadence. Unlike the MongoDB Node.js driver's collection object, this library focuses on serializable metadata with helper methods for UI display.

npm install mongodb-collection-model
INSTALL
IMPORT
SIG · MONGODB-COLLECTION
M
mongodb-collection-model
databasejavascriptv5.35.0
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.

default
import CollectionModel from 'mongodb-collection-model'
const CollectionModel = require('mongodb-collection-model').default
Default export is the model class. For CJS use 'const CollectionModel = require('mongodb-collection-model')'.
CollectionModelOptions
import { CollectionModelOptions } from 'mongodb-collection-model'
import CollectionModelOptions from 'mongodb-collection-model'
Type export for options interface.
CollectionModel
import { CollectionModel } from 'mongodb-collection-model'
import CollectionModel from 'mongodb-collection-model'
Named export also available, but default export is common.

Creates a collection model instance from metadata, showing property access.

import CollectionModel from 'mongodb-collection-model'; const collectionInfo = { _id: 'test.myCollection', name: 'myCollection', database: 'test', document_count: 1000, storage_size: 1048576, indexes: [{ name: '_id_', key: { _id: 1 }, unique: true }] }; const model = new CollectionModel(collectionInfo); console.log(model.name); // 'myCollection' console.log(model.document_count); // 1000 console.log(model.indexes.length); // 1
Debug
Known issues
breakingVersion 4.0.0 changed the constructor signature from (attrs, options) to (data). The previous second argument 'options' was removed.
fix
Update calls to 'new CollectionModel(data)' without options parameter.
affects: <4.0.0
gotchaThe model does not perform data validation on instantiation. Invalid or missing fields may cause runtime errors when accessing properties.
fix
Always provide complete metadata object as documented.
affects: >=4.0.0
deprecatedThe 'status' property was deprecated in v5.0.0. Use 'isRunning' or 'isPaused' instead.
fix
Use 'model.isRunning' and 'model.isPaused' methods.
affects: >=5.0.0
breakingIn v5.0.0, the 'indexes' field changed from an array of objects to an array of IndexModel instances.
fix
When setting indexes, provide IndexModel instances or use the helper method 'createIndex'.
affects: <5.0.0
Errors
Common errors & fixes
TypeError: CollectionModel is not a constructor
Using default import incorrectly with CommonJS require.
fix
Use 'const CollectionModel = require('mongodb-collection-model');' (no .default).
Cannot find module 'mongodb-collection-model'
Package not installed or import path is wrong.
fix
Run 'npm install mongodb-collection-model' and ensure import path is correct.
Property 'document_count' does not exist on type 'CollectionModel'
Using TypeScript strict mode with older version not shipping types.
fix
Upgrade to v5.0.0 or later, which includes TypeScript types.
Upgrade
Version history
5.35.0latest on npm
Audit
Dependencies
mongodb-js-utilsrequiredUtility functions used across mongodb-js packages
bsonrequiredBSON types for MongoDB documents
Agent activity
6 hits · last 30 days
node
6
Resources
mongodb-collection-model — npm install mongodb-collection-model · libregistry