---
title: MongoDB tenancy
editUrl: https://github.com/Cratis/Arc.TypeScript/edit/main/Documentation/mongodb/tenancy.md
description: How withMongoDB chooses a database and server for each tenant, and what a single-tenant application configures.
---


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.

## Database per tenant

| Configuration | Tenant `default` | Tenant `acme` |
| --- | --- | --- |
| `database: 'tasks'` | `tasks` | `tasks+acme` |
| `databaseNameResolver: tenant => \`tasks_${tenant}\`` | `tasks_default` | `tasks_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.

## Server per tenant

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

## Single-tenant applications

Configure Arc tenancy with a fixed tenant of `default`:

```typescript
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.

## Isolation is not authorization

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](/arc/backend/typescript/tenancy/).

## Related

- [Get started with MongoDB](/arc/backend/typescript/mongodb/getting-started/)
- [Tenant resolvers](/arc/backend/typescript/tenancy/resolvers/)
