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-mongodbNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Instantiates MongoDbConnector, connects to a single database, performs a findOne query, then disconnects.
Ensure your process gracefully handles SIGTERM or use a try-finally block to perform cleanup before calling disconnect.
Use an explicit migration script instead of relying on 'init' parameter.
Always provide a second argument (e.g., 'from-models' or a specific migration key).
Use require() instead of import. For TypeScript, use import { MongoDbConnector } from 'chpr-mongodb' with allowSyntheticDefaultImports: false.Upgrade MongoDB to 3.2+ or avoid using document validation schemas.
Change import MongoDbConnector from 'chpr-mongodb' to const { MongoDbConnector } = require('chpr-mongodb') or use TypeScript with allowSyntheticDefaultImports: false.Check the database URL and ensure the replica set is healthy. Use a direct connection for development.
Replace migrate('update', 'init') with a proper migration file or use migrate('update', 'from-models').