Hi everyone,
I’m migrating a multi-tenant app from Node/Golang to Phoenix/Elixir. Here’s how our data is set up:
- Each tenant has a separate MongoDB database (tenant_${tenant_id}).
- There’s a master DB with metadata about tenants.
- We don’t use schema validation—collections are schema-less and structure is only enforced by the application.
In my old stack, I could connect to any tenant’s DB as needed. In Elixir, I see the mongodb_driver
requires the DB name when starting the connection/pool, usually at app boot.
My main questions:
- How do Elixir/Phoenix apps usually handle selecting and connecting to the correct tenant database at runtime?
- Is it common to start a connection pool per tenant, or are there better patterns for this?
- Any advice, examples, or “gotchas” from folks who have done this before?
Appreciate any guidance or sample code. Thanks in advance!