Registry / database / veden-mongodb

veden-mongodb

JSON →
library1.4.0jsnpmunverified

A lightweight MongoDB client wrapper for Node.js that simplifies CRUD operations, aggregation, and transaction management. Current version is 1.4.0, with irregular release cadence. It provides a promise-based API with methods like find, insert, update, delete, aggregate, and transaction support. Unlike native MongoDB driver, it reduces boilerplate by accepting a parameter object for database, collection, limits, and field projection. It also includes a startTransaction helper that handles retries and commit/abort logic.

npm install veden-mongodb
INSTALL
IMPORT
SIG · VEDEN-MONGODB
V
veden-mongodb
databasejavascriptv1.4.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.

MongoDatabase
const { MongoDatabase } = require('veden-mongodb')
import { MongoDatabase } from 'veden-mongodb'
Package uses CommonJS only; ES module import is not supported.
MongoDatabase (default import)
const MongoDatabase = require('veden-mongodb').MongoDatabase
const MongoDatabase = require('veden-mongodb')
Package exports an object with MongoDatabase property, not a default export.
TypeScript types
import type { MongoDatabase } from 'veden-mongodb'
import { MongoDatabase } from 'veden-mongodb'
Types are not published; use any or define custom types.

Connects to a MongoDB instance and performs a find operation with field selection, exclusion, sort, and limit.

const { MongoDatabase } = require('veden-mongodb'); const db = new MongoDatabase({ DB_HOSTS: 'localhost', DB_REPLICA_SET: 'test', DB_USER: 'admin', DB_PASS: 'secret123' }); const params = { database: 'users', collection: 'user', limit: 10, fields: ['username', 'email'], exclude_fields: ['_id'], sort: { field: '_id', order: 'asc' } }; db.find(params, { email: /@gmail\.com$/ }).then(result => { console.log(result); }).catch(err => { console.error(err); });
Debug
Known issues
breakingIn version 1.3.0, the transaction callback signature changed: previously passed (err, result) but now expects async/await returning result.
fix
Update transaction callbacks to return a promise with the desired result.
affects: >=1.3.0
deprecatedThe DB_HOSTS option currently supports a single host only; multi-host replica set strings are not parsed correctly. This behavior may change in future versions.
fix
Ensure DB_HOSTS contains a single host:port; if using replica sets, specify the set in DB_REPLICA_SET.
affects: <1.5.0
gotchaThe find method returns an empty array when no documents match, but count returns 0. Ensure you check lengths/emptyness appropriately.
fix
Use db.count() to check if documents exist before fetching.
affects: >=1.0.0
gotchaThe `exclude_fields` parameter overrides `fields` if both are specified. Only one should be used to avoid unexpected results.
fix
Use either fields (inclusive) or exclude_fields (exclusive), not both.
affects: >=1.0.0
breakingIn version 1.4.0, the insertOne return changed: previously returned the inserted document's _id, now returns an object with _id and result properties.
fix
Access the _id via result._id instead of the direct return value.
affects: >=1.4.0
Errors
Common errors & fixes
TypeError: MongoDatabase is not a constructor
Importing incorrectly: using default import instead of destructuring.
fix
Use const { MongoDatabase } = require('veden-mongodb');
TypeError: Cannot destructure property 'MongoDatabase' of 'require(...)' as it is undefined.
Package not installed or typo in package name.
fix
Run `npm install veden-mongodb` and ensure the package name is spelled correctly.
MongoError: Authentication failed.
Wrong DB_USER or DB_PASS in MongoDatabase constructor, or no authentication database specified.
fix
Ensure credentials are correct and add DB_AUTH_SOURCE if using a non-admin auth database.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies
mongodbrequiredCore MongoDB Node.js driver used for all database operations
Agent activity
19 hits · last 30 days
node
14
Meta
2
OpenAI (training)
1
Resources
veden-mongodb — npm install veden-mongodb · libregistry