JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2577
  • Score
    100M100P100Q134078F
  • License MIT

MongoDB persistence for Aedes

Package Exports

  • aedes-persistence-mongodb

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aedes-persistence-mongodb) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

aedes-persistence-mongodb

.github/workflows/ci.yml Dependencies Status devDependencies Status
Known Vulnerabilities Coverage Status NPM version NPM downloads

Aedes persistence, backed by MongoDB.

See aedes-persistence for the full API, and Aedes for usage.

Install

npm i aedes aedes-persistence-mongodb --save

API

aedesPersistenceMongoDB([opts])

Creates a new instance of aedes-persistence-mongodb. It accepts a connections string url or you can pass your existing db object. Also, you can choose to set a ttl (time to live) for your subscribers or packets. This option will help you to empty your db from keeping useless data.

Options

  • url: The MongoDB connection url
  • ttl: Used to set a ttl (time to live) to documents stored in collections
    • packets: Could be an integer value that specify the ttl in seconds of all packets collections or an Object that specifies for each collection its ttl in seconds. Packets collections are: incoming, outgoing, retained, will.
    • susbscriptions: Set a ttl (in seconds)
  • db: Existing MongoDB instance (if no url option is specified)
  • dropExistingIndexes: Flag used to drop any exsisting index previously created on collections (except default index _id)

Examples

aedesPersistenceMongoDB({
  url: 'mongodb://127.0.0.1/aedes-test', // Optional when you pass db object
  // Optional ttl settings
  ttl: {
      packets: 300, // Number of seconds
      subscriptions: 300,
  }
})

With the previous configuration all packets will have a ttl of 300 seconds. You can also provide different ttl settings for each collection:

ttl: {
      packets: {
        incoming: 100,
        outgoing: 100,
        will: 300,
        retained: -1
      }, // Number of seconds
      subscriptions: 300,
}

If you want a specific collection to be persistent just set a ttl of -1 or null or undefined.

If you want to reuse an existing MongoDb instance just set the db option:

aedesPersistenceMongoDB({
 db:db
})

With mongoose:

aedesPersistenceMongoDB({
 db: mongoose.connection.useDb('myDbName').db
})

License

MIT