Registry / database / mongodb-extension

mongodb-extension

JSON →
library0.3.5jsnpmunverified

A lightweight TypeScript-first MongoDB extension providing typed helpers and utilities for common MongoDB operations. Current stable version 0.3.5, released monthly. Designed for type-safe database interactions with minimal overhead, offering schema validation stubs and query builders. Differentiates from Mongoose by focusing on direct MongoDB driver integration with TypeScript types rather than full ODM features.

npm install mongodb-extension
INSTALL
IMPORT
SIG · MONGODB-EXTENSION
M
mongodb-extension
databasejavascriptv0.3.5
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.

MongoClient
import { MongoClient } from 'mongodb-extension'
const MongoClient = require('mongodb-extension')
Named export; ESM only. Use with TypeScript for typings.
connect
import { connect } from 'mongodb-extension'
import connect from 'mongodb-extension'
Named export, not default. Uses existing MongoDB client.
QueryBuilder
import { QueryBuilder } from 'mongodb-extension'
import { QueryBuilder } from 'mongodb'
Custom query builder, not part of native driver.

Shows connecting to MongoDB and using QueryBuilder for type-safe queries.

import { MongoClient, connect, QueryBuilder } from 'mongodb-extension'; async function run() { const uri = process.env.MONGO_URI ?? 'mongodb://localhost:27017'; const client = new MongoClient(uri); await client.connect(); const db = client.db('test'); const collection = db.collection('users'); // Use QueryBuilder const query = new QueryBuilder() .filter({ age: { $gte: 18 } }) .sort({ name: 1 }) .limit(10) .build(); const results = await collection.find(query).toArray(); console.log(results); await client.close(); } run().catch(console.error);
Debug
Known issues
breakingThe build() method returns a plain object since v0.3.0 instead of a custom query instance
fix
Update code to treat query as plain object directly passed to find()
affects: >=0.3.0
deprecatedThe old schema validation helper validateSchema() is deprecated since v0.3.5, use validate() instead
fix
Replace validateSchema() calls with validate()
affects: >=0.3.5
gotchaconnect() function requires an existing MongoClient instance; it does not create a new connection
fix
Initialize a MongoClient first, then pass it to connect()
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: mongo_extension_1.connect is not a function
Incorrect import: using default import instead of named import
fix
Use import { connect } from 'mongodb-extension'
Cannot find module 'mongodb-extension' or its corresponding type declarations
Missing TypeScript type definitions or incorrect module resolution
fix
Ensure 'mongodb-extension' is installed and 'module' in tsconfig is set to 'node' or 'node16'
Upgrade
Version history
0.3.5latest on npm
Audit
Dependencies
mongodbrequiredPeer dependency for MongoDB driver
Agent activity
6 hits · last 30 days
node
6
Resources
mongodb-extension — npm install mongodb-extension · libregistry