📘
@node-test/bus
  • @node-ts/bus
  • Getting started
    • Installation
    • Handling messages
    • Shutting down cleanly
  • Reference
    • Bus
    • BusConfiguration
    • BusInstance
  • Getting help
  • Guide
    • Messages
      • Events
      • Commands
      • System messages
    • Message attributes
      • Correlation id
      • Attributes
      • Sticky attributes
    • Workflows
      • Creating a workflow
      • Starting
      • Handling
      • State
      • Completing
      • Example
    • Transports
      • RabbitMQ
      • Amazon SQS
      • Redis
      • Custom transports
    • Persistence
      • Postgres
      • MongoDB
      • Creating a persistence
    • Serializers
      • Class serializer
    • Loggers
      • Custom loggers
    • Middleware
    • Lifecycle hooks
    • Retry Strategies
    • Dependency injection
    • Long running processes
Powered by GitBook
On this page

Was this helpful?

  1. Guide
  2. Persistence

MongoDB

@node-ts/bus-mongodb provides a persistence adapter based on Mongo DB that's used when storing workflow state.

Installation

Install the @node-ts/bus-mongodb package

npm install @node-ts/bus-mongodb

Create a new MongodbPersistence instance and provide it to the bus configuration.

import { Bus } from '@node-ts/bus-core'
import { MongodbPersistence, MongodbConfiguration } from '@node-ts/bus-mongodb'

const configuration: MongodbConfiguration = {
  connection: 'mongodb://localhost:27017',
  databaseName: 'workflows'
}
const mongodbPersistence = new MongodbPersistence(configuration)

// Configure bus to use mongodb as a persistence
const run = async () => {
  await Bus
    .configure()
    .withPersistence(mongodbPersistence)
    .initialize()
}
run.then(() => void)
PreviousPostgresNextCreating a persistence

Last updated 2 years ago

Was this helpful?