Registry / database / mongodb-if

mongodb-if

JSON →
library1.4.4jsnpmunverified

A wrapper around the official MongoDB Node.js driver providing a simplified interface for common CRUD operations. Version 1.4.4, last updated in 2020, with low release cadence. Supports TypeScript with bundled type definitions. Differentiates by offering a class-based handler with automatic connection management and a set of convenience methods for single/multiple document operations. However, it relies on the deprecated MongoDB driver v3.x API and has not been updated to support newer MongoDB features or driver v4/v5 breaking changes.

npm install mongodb-if
INSTALL
IMPORT
SIG · MONGODB-IF
M
mongodb-if
databasejavascriptv1.4.4
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.

MongoDBHandler
import { MongoDBHandler } from 'mongodb-if'
import MongoDBHandler from 'mongodb-if'
MongoDBHandler is a named export, not a default export.
MongoDBInterface
import { MongoDBInterface } from 'mongodb-if'
TypeScript interface for handler options, only available when using TypeScript.
MongoDBListInterface
import { MongoDBListInterface } from 'mongodb-if'
TypeScript interface for database list items.

Shows setup of MongoDBHandler with environment variable for URL, connecting, inserting a document, and disconnecting.

import { MongoDBHandler } from 'mongodb-if'; const dbHandler = MongoDBHandler({ connectionDomain: process.env.MONGO_URL ?? 'mongodb://localhost:27017', connectionOptions: {}, dbNameList: ['mydb'], dbListOptions: [{}] }); async function run() { await dbHandler.connect(); const result = await dbHandler.addDataItem({ collectionName: 'users', data: { name: 'Alice', age: 30 } }); console.log('Inserted:', result); await dbHandler.disconnect(); } run().catch(console.error);
Debug
Known issues
deprecatedDepends on mongodb driver v3.x which is deprecated. Driver v4+ uses a different API.
fix
Consider migrating to the official mongodb driver directly or look for a maintained wrapper.
affects: >=1.0.0
gotchaMongoDBHandler requires dbNameList and dbListOptions arrays to be the same length; mismatched lengths cause runtime errors.
fix
Always ensure both arrays have the same length and corresponding entries.
affects: >=1.0.0
gotchagetDataItemsMany with empty or missing query returns all documents from the collection; developers may unintentionally expose large datasets.
fix
Always pass explicit query or set limit to avoid retrieving entire collection.
affects: >=1.0.0
deprecatedThe driver version used does not support the new Unified Topology; connection options like useNewUrlParser and useUnifiedTopology are silently ignored or cause warnings.
fix
Downgrade to mongodb driver v3.6.x or remove those options if using newer driver.
affects: >=1.0.0
gotchaThe connect() method returns true even if some databases fail to connect, as long as at least one succeeds.
fix
Check each database connection status individually using getDatabaseObjectList after connect.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: MongoDBHandler is not a constructor
Incorrect import style: using default import instead of named import.
fix
Use import { MongoDBHandler } from 'mongodb-if'
MongoError: bad auth Authentication failed.
Missing or incorrect authentication credentials in connectionOptions.
fix
Add auth like { user: 'admin', password: 'pass' } in connectionOptions or use a connection string with credentials.
TypeError: Cannot read property 'collection' of undefined
dbNameList contains a name not connected properly; database object is undefined.
fix
Ensure dbNameList entries match actual database names and that connect() resolved successfully.
Error: connect ECONNREFUSED 127.0.0.1:27017
MongoDB server is not running at the specified connectionDomain.
fix
Start MongoDB server or update connectionDomain to point to a running instance.
Upgrade
Version history
1.4.4latest on npm
Audit
Dependencies
mongodbrequiredCore MongoDB driver dependency
Agent activity
7 hits · last 30 days
node
6
Resources
mongodb-if — npm install mongodb-if · libregistry