Compare

Stratum + MongoDB

Document database with flexible schema

MongoDB is the most widely used document database in Node.js applications. @stratum-hq/mongodb is the only Node.js multi-tenancy library that supports both PostgreSQL and MongoDB -- giving teams running Mongoose or the native driver first-class tenant isolation. The control plane (tenant hierarchy, config inheritance, audit log) remains in PostgreSQL via @stratum-hq/lib. MongoDB carries your application documents, scoped per tenant through a Mongoose plugin or adapter.

Feature comparison

Capability MongoDB Stratum
Isolation strategies Manual where: { tenantId } on every query 3 strategies: shared collection, collection-per-tenant, database-per-tenant
Tenant scoping Application-level only — no RLS equivalent Mongoose plugin auto-scopes all queries
Config inheritance Not available Built-in via PostgreSQL control plane
GDPR purge Build it yourself purgeTenantData() for all 3 strategies
Audit logging Manual hooks Every mutation, actor-attributed (via PG control plane)
Security enforcement Application-level (no DB-level RLS) Application-level for shared/collection; DB-level for database-per-tenant
Control plane None PostgreSQL via @stratum-hq/lib (tenant hierarchy, config, audit)
Mongoose support Native Plugin for automatic tenant scoping

Getting started

mongodb-with-stratum.ts
import mongoose from "mongoose";
import { Stratum } from "@stratum-hq/lib";
import { MongoSharedAdapter } from "@stratum-hq/mongodb";
import { MongoClient } from "mongodb";

// Control plane: tenant hierarchy lives in PostgreSQL
const stratum = new Stratum({ pool });
await stratum.initialize();

// MongoDB adapter for document isolation
const mongo = new MongoClient(process.env.MONGODB_URI);
const adapter = new MongoSharedAdapter({
  client: mongo, databaseName: "myapp",
});

// Tenant created in PG control plane
const tenant = await stratum.createTenant({
  name: "Acme", slug: "acme"
});

// Scoped collection auto-injects tenant_id into every query
const orders = adapter.scopedCollection(tenant.id, "orders");
await orders.find({}); // only returns this tenant's documents

Things to know

Start building with MongoDB + Stratum

npm install @stratum-hq/lib pg