Registry / database / moleculer-db-adapter-mongo

moleculer-db-adapter-mongo

JSON →
library0.5.0jsnpmunverified

MongoDB native adapter for the Moleculer DB service, version 0.5.0 as of the latest release. It provides schemaless MongoDB integration for Moleculer microservices, using MongoDB Node.js driver v3.0. Unlike Mongoose-based alternatives, this adapter does not enforce schemas, making it suitable for flexible document models. Released under MIT license, maintained by MoleculerJS, with TypeScript type definitions included. The package depends on moleculer-db and moleculer frameworks.

npm install moleculer-db-adapter-mongo
INSTALL
IMPORT
SIG · MOLECULER-DB-ADAPT
M
moleculer-db-adapter-mongo
databasejavascriptv0.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.

MongoDBAdapter
const MongoDBAdapter = require('moleculer-db-adapter-mongo');
import { MongoDBAdapter } from 'moleculer-db-adapter-mongo';
This package uses CommonJS. Do not use ES module import syntax as it will fail.
MongoDBAdapter (default export)
const MongoDBAdapter = require('moleculer-db-adapter-mongo');
const { MongoAdapter } = require('moleculer-db-adapter-mongo');
The export is as default, so destructuring with wrong name will result in undefined.
MongoDBAdapter.TypeScript
import MongoDBAdapter from 'moleculer-db-adapter-mongo';
import { MongoDBAdapter } from 'moleculer-db-adapter-mongo';
TypeScript with esModuleInterop: true allows default import, but named import will not work.

Create a Moleculer broker, define a posts service with MongoDB adapter, create a document, then find all documents.

const { ServiceBroker } = require('moleculer'); const DbService = require('moleculer-db'); const MongoDBAdapter = require('moleculer-db-adapter-mongo'); const broker = new ServiceBroker(); broker.createService({ name: 'posts', mixins: [DbService], adapter: new MongoDBAdapter('mongodb://127.0.0.1/moleculer-demo'), collection: 'posts' }); broker.start() .then(() => broker.call('posts.create', { title: 'My first post', content: 'Lorem ipsum...', votes: 0 })) .then(() => broker.call('posts.find').then(console.log));
Debug
Known issues
breakingMongoDBNativeAdapter class renamed to MongoDBAdapter in v0.5.0
fix
Use 'MongoDBAdapter' instead of 'MongoDBNativeAdapter'
affects: >=0.5.0
deprecatedMongoDB driver v3.0 is outdated, consider upgrading to v4+ manually
fix
If you need newer MongoDB features, you may need to use a different adapter or override the driver.
affects: <0.6.0
gotchaAdapter requires both moleculer and moleculer-db to be installed as peer dependencies
fix
Install both: npm install moleculer moleculer-db
affects: >=0.4.0
gotchaCommonJS only (no ES module support); using import will break
fix
Use require() or configure your bundler to use CommonJS
affects: >=0.0.1
deprecatedConnection string and options constructor signature deprecated; future versions may use object config
fix
Refer to documentation for any changes in constructor format
affects: >=0.5.0
Errors
Common errors & fixes
Cannot find module 'moleculer-db-adapter-mongo'
Missing npm package installation
fix
npm install moleculer-db moleculer-db-adapter-mongo
MongoDBAdapter is not a constructor
Importing as ES module or destructuring incorrectly
fix
Use const MongoDBAdapter = require('moleculer-db-adapter-mongo');
MongoError: Authentication failed.
Missing or incorrect credentials in MongoDB URI
fix
Provide valid credentials: mongodb://user:password@host/db
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies
moleculerrequiredPeer dependency required for the Moleculer framework
moleculer-dbrequiredRequired peer dependency for database service mixin
Agent activity
2 hits · last 30 days
node
2
Resources
moleculer-db-adapter-mongo — npm install moleculer-db-adapter-mongo · libregistry