Registry / database / mongodb-addons

mongodb-addons

JSON →
library1.2.0jsnpmunverified

A utility library (v1.2.0) providing MongoDB helpers for join/merge operations, GridStore file handling, a MongoBuilder query builder, and ObjectID parsing. Designed to work with the native MongoDB Node.js driver, this package offers a fluent API for building filters, pagination, sorting, and field selection. It is especially associated with the total.js web framework. The package has not seen updates since its initial release and lacks modern driver support, making it a legacy option for simple MongoDB interactions without official Mongoose or MongoDB driver aggregation pipelines.

npm install mongodb-addons
INSTALL
IMPORT
SIG · MONGODB-ADDONS
M
mongodb-addons
databasejavascriptv1.2.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.

MongoBuilder
const MongoBuilder = require('mongodb-addons').MongoBuilder;
import { MongoBuilder } from 'mongodb-addons';
Package does not support ESM; use CommonJS require.
GridStore.writeFile
require('mongodb-addons'); // GridStore becomes global
const { GridStore } = require('mongodb-addons');
GridStore is attached to global scope upon requiring the package; do not destructure.
ObjectID.parse
require('mongodb-addons'); // ObjectID.parse becomes globally available
const { ObjectID } = require('mongodb-addons');
ObjectID is also global; no named import possible.

Shows how to use join/merge on a cursor and use MongoBuilder for filtering and sorting.

const MongoClient = require('mongodb').MongoClient; require('mongodb-addons'); // Makes GridStore, ObjectID globally available const MongoBuilder = require('mongodb-addons').MongoBuilder; async function run() { const client = await MongoClient.connect('mongodb://localhost:27017'); const db = client.db('test'); const collection = db.collection('products'); // JOIN example collection.find().join('idcategory', 'category', 'categories-collection').merge(function(err, docs) { if (err) throw err; console.log(docs); }); // MongoBuilder example const builder = new MongoBuilder(0, 10); builder.where('age', '>=', 18); builder.sort('name', true); builder.find(collection).toArray(function(err, docs) { if (err) throw err; console.log(docs); client.close(); }); } run();
Debug
Known issues
deprecatedPackage has not been maintained since 2015; no support for MongoDB 3.x+ native driver APIs or ES modules.
fix
Migrate to using the MongoDB aggregation pipeline with $lookup for joins and modern query builders.
affects: >=1.0.0
gotchaGridStore and ObjectID are attached to the global object when requiring the package, which can cause pollution and conflicts.
fix
Use a scoped variable instead: const { GridStore } = require('mongodb-addons'); does not work; you must explicitly assign from global after require.
affects: >=1.0.0
gotchaThe join() method relies on the deprecated cursor.nextObject() stream style; may not work with modern MongoDB driver versions.
fix
Use $lookup in aggregation pipeline instead.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: ObjectID is not a constructor
ObjectID is not imported or not global; using import { ObjectID } from 'mongodb-addons' yields undefined.
fix
Ensure you require the package: require('mongodb-addons'); then use the global ObjectID.
Cannot find module 'mongodb-addons'
Package not installed or incorrectly imported in an ESM project.
fix
Install with npm: npm install mongodb-addons; use require() not import since package lacks ESM support.
TypeError: db.collection(...).find(...).join is not a function
The package is not required before using join method, or the cursor is not from a proper MongoDB collection.
fix
Add require('mongodb-addons'); at the top of your file to extend the cursor prototype.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
mongodbrequiredDirect peer dependency for MongoDB operations
Agent activity
5 hits · last 30 days
node
4
Resources
mongodb-addons — npm install mongodb-addons · libregistry