Registry / messaging / aedes-persistence-mongodb

aedes-persistence-mongodb

JSON →
library9.4.2jsnpmunverified

MongoDB persistence layer for the Aedes MQTT broker. Version 9.4.2 requires Node.js >=20. Supports flexible TTL per collection (incoming, outgoing, retained, will, subscriptions) or per-message, and can use either a connection string or an existing MongoDB instance. Integrates with Mongoose via the native db object. The persistence follows the aedes-persistence interface and is intended for production MQTT deployments needing durable session storage. Maintained under the moscajs organization with active CI and coverage.

npm install aedes-persistence-mongodb
INSTALL
IMPORT
SIG · AEDES-PERSISTENCE-
A
aedes-persistence-mongodb
messagingjavascriptv9.4.2
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.

aedesPersistenceMongoDB
import aedesPersistenceMongoDB from 'aedes-persistence-mongodb'
const persistence = require('aedes-persistence-mongodb')
Default export. CommonJS require works but is not recommended for ESM-only projects.
AedesPersistenceMongoDB
import AedesPersistenceMongoDB from 'aedes-persistence-mongodb'
import { AedesPersistenceMongoDB } from 'aedes-persistence-mongodb'
TypeScript types are not provided; this symbol is the constructor function itself, not a named export.
aedes
import Aedes from 'aedes'
const Aedes = require('aedes')
aedes is a peer dependency and must be imported separately.

Creates an Aedes MQTT broker with MongoDB persistence, using environment variable for connection URL and setting TTLs.

import Aedes from 'aedes'; import aedesPersistenceMongoDB from 'aedes-persistence-mongodb'; const persistence = aedesPersistenceMongoDB({ url: process.env.MONGO_URL ?? 'mongodb://localhost:27017/mqtt', ttl: { packets: 3600, subscriptions: 7200 } }); const broker = new Aedes({ persistence }); broker.on('client', (client) => { console.log('Client connected:', client.id); }); await new Promise((resolve, reject) => { broker.listen(1883, (err) => { if (err) reject(err); else resolve(); }); });
Debug
Known issues
breakingRequires Node.js >=20.0.0. Using older Node versions will cause errors.
fix
Update Node.js to version 20 or later.
affects: >=9.0.0
gotchattlAfterDisconnected changes the TTL index to use client disconnect time. When toggling this option, dropExistingIndexes must be true to rebuild indexes.
fix
Set dropExistingIndexes: true when changing ttlAfterDisconnected or TTL durations.
affects: >=9.0.0
gotchaIf you pass both url and db options, url is ignored. Ensure you only provide one.
fix
Provide either url or db, not both.
affects: >=1.0.0
Errors
Common errors & fixes
MongoServerError: E11000 duplicate key error collection
Duplicate client ID due to unclean reconnection without proper persistence cleanup.
fix
Ensure that aedes-persistence-mongodb is correctly configured with TTL or that clients disconnect cleanly.
TypeError: aedesPersistenceMongoDB is not a constructor
Using a named import instead of default import.
fix
Use `import aedesPersistenceMongoDB from 'aedes-persistence-mongodb'`.
Error: Cannot find module 'aedes'
Missing peer dependency.
fix
Install aedes: `npm install aedes`.
Upgrade
Version history
9.4.2latest on npm
Audit
Dependencies
aedesrequiredpeer dependency required to use this persistence with the Aedes broker
mongodbrequiredMongoDB driver used internally for database operations
Agent activity
28 hits · last 30 days
node
24
OpenAI (training)
1
Resources
aedes-persistence-mongodb — npm install aedes-persistence-mongodb · libregistry