StepflowStepflow

MongoDB Storage

Document-based storage adapter with real-time Change Streams

MongoDB Storage

The @stepflowjs/storage-mongodb adapter provides a document-based storage backend using MongoDB. It uses MongoDB's flexible schema for storing workflow state and leverages Change Streams for real-time updates.

Installation

pnpm add @stepflowjs/storage-mongodb

Usage

import { Stepflow } from "@stepflowjs/core";
import { MongoStorageAdapter } from "@stepflowjs/storage-mongodb";

const stepflow = new Stepflow({
  storage: new MongoStorageAdapter({
    url: process.env.MONGODB_URL,
    database: "stepflow_db",
    // Optional: collection prefix
    collectionPrefix: "sf_",
  }),
});

Configuration Options

OptionTypeDescription
urlstringMongoDB connection URL (Required)
databasestringDatabase name (default: stepflow)
collectionPrefixstringPrefix for all collections (default: "")

Features

  • Flexible Schema: Naturally handles complex workflow payloads and metadata.
  • Change Streams: Uses MongoDB Change Streams to provide real-time execution updates.
  • TTL Indexes: Leverages MongoDB's TTL indexes for automatic cleanup of expired locks.
  • Scalable: Easily scales with MongoDB's sharding and replication capabilities.

Environment Variables

MONGODB_URL=mongodb://user:password@localhost:27017/stepflow?replicaSet=rs0

Note: Change Streams require a replica set or sharded cluster.

On this page