Registry / database / mongodb-instance-model

mongodb-instance-model

JSON →
library12.49.0jsnpmunverified

A MongoDB instance model used internally by MongoDB Compass to represent database instances with properties like host, port, topology, and replica set state. Version 12.49.0 is current, with frequent releases tied to Compass. It is a core abstraction within the Compass data layer but not intended for standalone use. Differentiates as a stateful model with change events, built on top of the MongoDB Node.js driver's topology monitoring.

npm install mongodb-instance-model
INSTALL
IMPORT
SIG · MONGODB-INSTANCE-M
M
mongodb-instance-model
databasejavascriptv12.49.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 InstanceModel from 'mongodb-instance-model';
const { InstanceModel } = require('mongodb-instance-model');
Package uses default export, no named export.
InstanceModel
import InstanceModel from 'mongodb-instance-model';
import { InstanceModel } from 'mongodb-instance-model';
Default export is named InstanceModel in declarations but imported as default.
InstanceModel type
import type InstanceModel from 'mongodb-instance-model';
import { InstanceModel } from 'mongodb-instance-model';
TypeScript users should use `import type` for type-only imports.

Creates an InstanceModel from a connected MongoClient's topology, listens for changes, and fetches instance data.

import InstanceModel from 'mongodb-instance-model'; import { MongoClient } from 'mongodb'; async function main() { const client = new MongoClient(process.env.MONGO_URI ?? 'mongodb://localhost:27017'); await client.connect(); const topology = client.topology; const model = new InstanceModel(topology); model.on('change', () => { console.log('Instance model changed:', model.toJSON()); }); await model.fetch(); console.log('Instance model:', model.toJSON()); await client.close(); } main().catch(console.error);
Debug
Known issues
gotchaInstanceModel constructor expects a Topology instance from the MongoDB Node.js driver (>=4.0), not a Db or MongoClient directly.
fix
Use `client.topology` after connecting the MongoClient.
affects: >=12.0.0
deprecatedSome older event names may be deprecated in favor of new ones; check source for exact mapping.
fix
Refer to the changelog for event name changes.
affects: >=11.0.0
breakingVersion 12.x dropped support for Node.js <14.
fix
Upgrade to Node.js 14 or later.
affects: >=12.0.0
Errors
Common errors & fixes
TypeError: InstanceModel is not a constructor
Attempting to import named export instead of default export.
fix
Use `import InstanceModel from 'mongodb-instance-model'` (no braces).
Error: topology must be a Topology instance
Passing a MongoClient or Db directly to the constructor.
fix
Pass `client.topology` after calling `client.connect()`.
Property 'topology' does not exist on type 'MongoClient'
Using TypeScript with older @types/mongodb where topology is not exposed.
fix
Update @types/mongodb to version >=4.0.0 or cast `(client as any).topology`.
Upgrade
Version history
12.49.0latest on npm
Audit
Dependencies
mongodb-js/mongodb-model-utilsoptionalUtility functions for model inheritance
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
mongodb-instance-model — npm install mongodb-instance-model · libregistry