Registry / messaging / mqemitter-mongodb

mqemitter-mongodb

JSON →
library9.1.0jsnpmunverified

MongoDB-based message queue emitter implementing the MQEmitter interface. Version 9.1.0, released regularly. It persists messages in MongoDB, supporting topics and payloads. Differentiators: leverages MongoDB for persistence and scaling, suitable for Node.js applications needing durable pub/sub messaging. Requires Node.js >=20.0.0. The package provides a simple API for emitting and subscribing to messages with an optional callback pattern.

npm install mqemitter-mongodb
INSTALL
IMPORT
SIG · MQEMITTER-MONGODB
M
mqemitter-mongodb
messagingjavascriptv9.1.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 mqemitter from 'mqemitter-mongodb'
const mqemitter = require('mqemitter-mongodb')
The package exports a factory function. Use ESM import for modern Node.js. CommonJS require is still supported.
mqemitter
import mqemitter from 'mqemitter-mongodb'
import { mqemitter } from 'mqemitter-mongodb'
The default export is the factory function. Named import does not exist.
MQEmitterMongoDB
import mqemitter from 'mqemitter-mongodb'
import { MQEmitterMongoDB } from 'mqemitter-mongodb'
The package does not export a class named MQEmitterMongoDB. Use the default export.

Creates a MongoDB-backed MQEmitter, subscribes to a topic, and emits a message with a callback.

import mqemitter from 'mqemitter-mongodb' const mq = mqemitter({ url: process.env.MONGO_URL ?? 'mongodb://127.0.0.1/mqemitter' }) const msg = { topic: 'hello world', payload: 'or any other fields' } mq.on('hello world', function (message, cb) { console.log('received:', message) cb() }) mq.emit(msg, function () { console.log('emitted') })
Debug
Known issues
gotchaThe callback passed to mq.on must not pass an error; the emitter cannot handle it.
fix
Ensure cb() is called without arguments (no error).
affects: >=1.0.0
deprecatedAuto-reconnect URL option 'auto_reconnect' may be deprecated in newer MongoDB drivers.
fix
Use modern MongoDB connection options instead of query parameters for auto reconnect.
affects: >=8.0.0
gotchaThe emitter will never return an error; errors must be handled elsewhere.
fix
Use connection error events or global error handlers to catch MongoDB errors.
affects: >=1.0.0
breakingNode.js version 20 is required; may break on older versions.
fix
Upgrade Node.js to >=20.0.0.
affects: 9.x
Errors
Common errors & fixes
TypeError: mqemitter is not a function
Using named import instead of default import
fix
Use `import mqemitter from 'mqemitter-mongodb'` instead of `import { mqemitter } from 'mqemitter-mongodb'`
MongoError: Authentication failed
Incorrect MongoDB credentials in the URL
fix
Ensure the MongoDB URL contains valid credentials, e.g., 'mongodb://user:pass@host/db'
TypeError: Cannot read properties of undefined (reading 'topic')
The message object passed to mq.emit is missing the 'topic' property
fix
Include a 'topic' string property in the message object, e.g., { topic: 'test', payload: 'data' }
MongooseError: The `uri` parameter to `openUri()` must be a string, got "undefined"
No MongoDB URL provided or URL is undefined
fix
Provide a valid MongoDB connection string via the `url` option
Upgrade
Version history
9.1.0latest on npm
Audit
Dependencies
mqemitterrequiredCore interface that this package implements
mongodbrequiredMongoDB driver for database operations
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources