Registry / database / chpr-mongodb

chpr-mongodb

JSON →
library4.0.1-force-exitjsnpmunverified

Wrapper around the native MongoDB Node.js driver designed to provide robust connection management for multi-database setups, with support for model definitions and migration patterns. The current stable version is 4.0.1-force-exit, requiring Node.js >=8.9 and MongoDB >=3.2. It enforces async/await patterns and ships with built-in deprecation warnings for certain migration methods. Key differentiators include forced exit on disconnect, background index creation (configurable), and documentation for migrating from version 2.

npm install chpr-mongodb
INSTALL
IMPORT
SIG · CHPR-MONGODB
C
chpr-mongodb
databasejavascriptv4.0.1-force-exit
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.

MongoDbConnector
const { MongoDbConnector } = require('chpr-mongodb')
const MongoDbConnector = require('chpr-mongodb')
CommonJS only; the package does not provide ESM exports. Named import is required.
default import
const { MongoDbConnector } = require('chpr-mongodb')
import MongoDbConnector from 'chpr-mongodb'
No default export - must use named import. ESM not supported.
MongoDbConnector (ESM attempt)
const { MongoDbConnector } = require('chpr-mongodb')
import { MongoDbConnector } from 'chpr-mongodb'
The package does not export ESM; will cause SyntaxError or undefined.

Instantiates MongoDbConnector, connects to a single database, performs a findOne query, then disconnects.

const { MongoDbConnector } = require('chpr-mongodb'); async function run() { const client = new MongoDbConnector({ databases: [{ name: 'test', url: process.env.MONGO_URL ?? 'mongodb://localhost:27017/test' }] }); await client.connect(); console.log('Connected successfully'); // Example usage with a model const db = client.getDb('test'); const collection = db.collection('users'); const user = await collection.findOne({}); console.log('User:', user); await client.disconnect(); } run().catch(console.error);
Debug
Known issues
breakingVersion 4.0.1-force-exit: The disconnect method now forcefully exits the process. This may cause unexpected shutdown in production environments.
fix
Ensure your process gracefully handles SIGTERM or use a try-finally block to perform cleanup before calling disconnect.
affects: >=4.0.0
deprecatedThe migrate('update', 'init') method is deprecated. It will be removed in a future version.
fix
Use an explicit migration script instead of relying on 'init' parameter.
affects: >=3.0.0
deprecatedCalling migrate('update') without a second parameter is deprecated.
fix
Always provide a second argument (e.g., 'from-models' or a specific migration key).
affects: >=3.0.0
gotchaThe package uses CommonJS require(). ES module imports will not work and will result in an undefined export.
fix
Use require() instead of import. For TypeScript, use import { MongoDbConnector } from 'chpr-mongodb' with allowSyntheticDefaultImports: false.
affects: *
gotchaIf MongoDB server is running a version older than 3.2, document validation features may cause runtime errors.
fix
Upgrade MongoDB to 3.2+ or avoid using document validation schemas.
affects: *
Errors
Common errors & fixes
TypeError: chpr_mongodb_1.default is not a constructor
Trying to import the package as an ESM default import, but the package exports named CommonJS.
fix
Change import MongoDbConnector from 'chpr-mongodb' to const { MongoDbConnector } = require('chpr-mongodb') or use TypeScript with allowSyntheticDefaultImports: false.
MongoError: can't find a master
Replica set connection string used but no primary available, or incorrect URI.
fix
Check the database URL and ensure the replica set is healthy. Use a direct connection for development.
DeprecationWarning: (node:12345) DeprecationWarning: migrate('update', 'init') is deprecated.
Using the deprecated migration signature.
fix
Replace migrate('update', 'init') with a proper migration file or use migrate('update', 'from-models').
Upgrade
Version history
4.0.1-force-exitlatest on npm
Audit
Dependencies
mongodbrequiredPeer dependency - native MongoDB driver version ^3.3.3 required
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
chpr-mongodb — npm install chpr-mongodb · libregistry