Registry / database / bedrock-mongodb

bedrock-mongodb

JSON →
library8.5.0jsnpmunverified

A Bedrock module that creates a simple MongoDB database and provides an easy API for creating and working with its collections. Current stable version is 8.5.0, targeting Node.js >=10 and requiring peer dependency bedrock ^4.3.0. It simplifies MongoDB setup in Bedrock applications with opinionated configuration for database name, host, port, authentication, and connection options. Supports URL-based configuration and Mongoose-like collection management via openCollections. Compared to raw mongodb driver usage, it integrates with Bedrock events and configuration system, handling database creation and user setup on startup.

npm install bedrock-mongodb
INSTALL
IMPORT
SIG · BEDROCK-MONGODB
B
bedrock-mongodb
databasejavascriptv8.5.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.

default import
const database = require('bedrock-mongodb');
import database from 'bedrock-mongodb';
Package uses CommonJS; ES modules not supported. Use require().
config.mongodb
const { config } = require('bedrock'); config.mongodb.name = 'my_project_dev';
const config = require('bedrock-mongodb').config;
Configuration is accessed via bedrock's config object, not exported by this module.
openCollections
const database = require('bedrock-mongodb'); database.openCollections(['myCollection'], callback);
const { openCollections } = require('bedrock-mongodb');
openCollections is a method on the default export, not a named export.

Demonstrates basic setup: configure MongoDB connection, open a collection after database ready event, and query it.

const bedrock = require('bedrock'); const database = require('bedrock-mongodb'); bedrock.config.mongodb.name = 'my_project_dev'; bedrock.config.mongodb.host = 'localhost'; bedrock.config.mongodb.port = 27017; bedrock.config.mongodb.username = 'my_project'; bedrock.config.mongodb.password = 'password'; bedrock.events.on('bedrock-mongodb.ready', function(callback) { database.openCollections(['collection1'], function(err) { if(err) return callback(err); database.collections.collection1.findOne({name: 'test'}, function(err, result) { if(err) return callback(err); console.log('Result:', result); callback(); }); }); }); bedrock.start();
Debug
Known issues
breakingVersion 8.0.0 dropped support for Node.js <10 and requires bedrock ^4.3.0.
fix
Upgrade to Node.js >=10 and bedrock ^4.3.0.
affects: >=8.0.0
deprecatedThe `authDB` option in connectOptions is deprecated; use `authSource` instead.
fix
Replace `connectOptions.authDB` with `connectOptions.authSource`.
affects: *
gotchaThe `bedrock-mongodb.ready` event must be listened on before calling bedrock.start().
fix
Register event handler before bedrock.start(); otherwise collections may not be opened.
affects: *
gotchaCollections are accessed via `database.collections` after they are opened; attempting to use a collection before openCollections callback will result in undefined.
fix
Access collections only inside the openCollections callback or after it completes.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'bedrock-mongodb'
Module not installed or peer dependency bedrock missing.
fix
Run 'npm install bedrock-mongodb bedrock' and ensure both are in node_modules.
MongoError: Authentication failed.
Incorrect username/password or authSource not set.
fix
Check config.mongodb.username/password and connectOptions.authSource; ensure MongoDB user exists.
TypeError: database.openCollections is not a function
Incorrect import: using named import instead of default require.
fix
Use `const database = require('bedrock-mongodb');`
Upgrade
Version history
8.5.0latest on npm
Audit
Dependencies
bedrockrequiredpeer dependency required for framework integration (events, config, start)
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
bedrock-mongodb — npm install bedrock-mongodb · libregistry