Skip to content

Connection resolution

Use connection resolution when each tenant’s MongoDB database lives somewhere your platform decides, or authenticates with its own credentials. For the concepts and the resolvers, read connection resolution first; for the endpoint an Http resolver calls, see the connection resolution contract.

This page configures resolution for MongoDB only. To configure it once for every storage, set it on Arc instead, as described in configure it once for the whole application. What you configure here replaces the application-wide configuration for MongoDB.

Keep Server and Database as they are, and resolve only who connects:

{
"Cratis": {
"MongoDB": {
"Server": "mongodb://cluster.example:27017",
"Database": "app",
"ConnectionResolution": {
"Identity": {
"Resolver": "Http",
"Http": {
"Endpoint": "https://platform.example/connections",
"Headers": { "X-Api-Key": "from-your-secret-store" }
}
}
}
}
}
}

The same in code:

builder.AddCratisArc(configureBuilder: arc => arc.WithMongoDB(
configureOptions: mongo => mongo.ConnectionResolution.Identity.UseHttp(new Uri("https://platform.example/connections"))));

Each request scope now resolves for its tenant. IMongoClient, IMongoDatabase and IMongoCollection<T> in that scope all come from the same resolution.

Resolved partEffect
ConnectionStringReplaces Server.
DatabaseReplaces the database name. Without it, the tenant database naming applies as before.
Identity.UserName and Identity.PasswordBecomes a SCRAM credential. It authenticates against the connection string’s authSource, else its database, else admin.
Identity.AccessTokenBecomes a MONGODB-OIDC credential. When the driver needs a new token, Arc resolves again, so a rotating token never needs a new client.
SchemaNot used by MongoDB.

Clients are shared per server and credential, never across credentials. A connection that fails to authenticate drops the cached resolution, and the next scope resolves fresh credentials.

Change-stream observation follows the same resolution, partitioned per server and database.

When placement follows a rule, you do not need an endpoint:

"ConnectionResolution": {
"Connection": {
"Resolver": "Template",
"Template": { "Database": "tenant-{tenant}" }
}
}