Several tenants in one cluster

Split your customers into tenants that only see their own databases.

Split your customers into tenants inside one cluster. Each user belongs to a tenant and only sees its databases.

Requirements

  • Access to teseladb admin and a tenant 0 user allowed to create users.

Create the tenant

Shell
teseladb admin tenant create acme

Create a user of the tenant

From a tenant 0 connection, the $tenant argument makes the command work in another tenant:

JavaScript
db.getSiblingDB("admin").runCommand({
  createUser: "acme-api",
  pwd: passwordPrompt(),
  roles: [{ role: "readWrite", db: "shop" }],
  $tenant: "acme",
});

Check

Log in as acme-api and run listDatabases. The answer shows only the databases of the acme tenant, even if the cluster holds databases of other tenants.

Common problems

  • tenant drop fails because the tenant still has databases or users. Drop them first.

See also