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
- MongoDB has no Row-Level Security equivalent -- isolation is enforced at the application layer. Use database-per-tenant for sensitive data requiring physical separation.
- The control plane (tenant hierarchy, config, audit log) always requires PostgreSQL via @stratum-hq/lib. MongoDB carries application documents only.
- For shared-collection strategy, add a compound index on { tenant_id, ...queryFields } to prevent full-collection scans.
- Database-per-tenant requires a connection pool per tenant -- configure pool limits to avoid exhausting MongoDB connections.
Start building with MongoDB + Stratum
npm install @stratum-hq/lib pg