Skip to content

MongoDB tenancy

Every Arc execution resolves a tenant, and the MongoDB collection you inject belongs to that tenant’s database. You decide the mapping; the package never falls back to a default database silently.

ConfigurationTenant defaultTenant acme
database: 'tasks'taskstasks+acme
databaseNameResolver: tenant => \tasks_${tenant}“tasks_defaulttasks_acme

Tenant names are normalized to lowercase before a database is chosen, including names returned by tenancy.resolve. A missing tenant or an empty database name fails the request.

serverResolver(tenantId, context) routes tenants to different MongoDB servers and must return a URI. It replaces client and server.

Configure Arc tenancy with a fixed tenant of default:

import { ArcApplication, TenantResolverType } from '@cratis/arc.core';
const builder = ArcApplication.createBuilder({ tenancy: { resolverType: TenantResolverType.Fixed, fixedTenantId: 'default' } });

With database: 'tasks', every request then uses the bare tasks database.

Choosing the tenant’s database does not prove the caller belongs to that tenant. Configure a membership check or derive the tenant from the principal; see Tenancy.