Registry / database / mubsub-nbb

mubsub-nbb

JSON →
library1.6.1jsnpmunverified

Mubsub is a pub/sub implementation for Node.js using MongoDB capped collections and tailable cursors. This fork (mubsub-nbb, published as @nodebb/mubsub) updates the original package for compatibility with mongodb 3.x driver. Version 1.6.1 is the latest stable release, maintained sporadically by NodeBB. It allows publishing events as documents into capped collections and supports event filtering via MongoDB queries. Key differentiators: leverages MongoDB's native tailable cursors for real-time notifications, supports flexible channel configuration (size, max, retry interval), and does not require additional infrastructure beyond MongoDB.

npm install mubsub-nbb
INSTALL
IMPORT
SIG · MUBSUB-NBB
M
mubsub-nbb
databasejavascriptv1.6.1
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.

mubsub
import mubsub from '@nodebb/mubsub';
const mubsub = require('mubsub');
Use the scoped @nodebb/mubsub package. The old mubsub package is deprecated.
Client
const client = mubsub(uri, options); // returns a Client instance
const client = new mubsub(uri);
mubsub is a factory function, not a constructor.
Channel
const channel = client.channel(name, options); // returns a Channel instance
const channel = mubsub.channel(name);
Call channel() on a client instance, not on the mubsub function.

Demonstrates creating a client, subscribing to events, publishing messages, and closing the connection.

import mubsub from '@nodebb/mubsub'; const client = mubsub('mongodb://localhost:27017/mubsub_example'); client.on('error', (err) => console.error('Client error:', err)); const channel = client.channel('test'); channel.on('error', (err) => console.error('Channel error:', err)); channel.subscribe('bar', (message) => { console.log(message.foo); // 'bar' }); channel.subscribe('baz', (message) => { console.log(message); // 'baz' }); setTimeout(() => { channel.publish('bar', { foo: 'bar' }); channel.publish('baz', 'baz'); }, 1000); setTimeout(() => { client.close(); }, 3000);
Debug
Known issues
breakingThe package name changed from 'mubsub' to '@nodebb/mubsub'. Install the scoped package.
fix
npm install @nodebb/mubsub
affects: >=1.0
deprecatedThe 'mubsub' package (original) is unmaintained. Use '@nodebb/mubsub' for mongodb 3.x compatibility.
fix
Switch to '@nodebb/mubsub'.
affects: <1.0
gotchaDo not remove capped collections while publishers are active; mongod may recreate it as an uncapped collection, breaking subscriptions.
fix
Ensure channels are only deleted when no publishers are active.
affects: *
gotchaCreating many channels (capped collections) is expensive; each channel maintains a tailable cursor polling loop.
fix
Limit the number of channels to avoid performance degradation.
affects: *
Errors
Common errors & fixes
TypeError: mubsub is not a function
Using the old 'mubsub' package (unscoped) or importing incorrectly.
fix
Run: npm install @nodebb/mubsub and import using: import mubsub from '@nodebb/mubsub';
MongoError: can't find collection
The capped collection for the channel was dropped or never created.
fix
Ensure the MongoDB connection URI points to a database that exists and has write permissions.
Error: Client is not connected to MongoDB
Calling channel() or publish() before the client connection is established.
fix
Wait for the client 'connect' event or ensure MongoDB is reachable.
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies
mongodbrequiredrequires mongodb driver (3.x compatible)
Agent activity
2 hits · last 30 days
node
2
Resources
mubsub-nbb — npm install mubsub-nbb · libregistry