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-mongodbUsage
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
| Option | Type | Description |
|---|---|---|
url | string | MongoDB connection URL (Required) |
database | string | Database name (default: stepflow) |
collectionPrefix | string | Prefix 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=rs0Note: Change Streams require a replica set or sharded cluster.