Skip to content

← Back to standards

MongoDB

MongoDB Atlas is our default application database for Fly-hosted APIs—customer and business data live here, not on Fly machines.

Fly runs the API; Atlas holds the data. MONGODB_URI and IP allowlists are set per tier, aligned with sacred branches and Fly app names.


UsePlain English
Application dataDocuments, orders, knowledge base content, product config—whatever the API owns
Per-environment databasesSeparate Atlas access per tier where policy requires isolation
IP-restricted accessAtlas allowlists the Fly app’s egress IPv4 when Network Access rules apply

Not every API uses Atlas—check each repo’s .env.example. Local dev may use a different URI; production paths use Atlas + Fly secrets.

Set with fly secrets set on each tier’s app—never commit real URIs to Git.

SecretPurpose
MONGODB_URIFull connection string (user, password, cluster, database) for that tier

Example:

Terminal window
fly secrets set MONGODB_URI='mongodb+srv://...' -a <fly-app-name>

See Fly checklist → Fly environment variables and egress note.

If Atlas uses IP Access List rules, the Fly app needs a dedicated egress IPv4:

Terminal window
fly ips allocate-egress --region iad -a <fly-app-name> --yes
fly ips list -a <fly-app-name> # type egress — not ingress

In Atlas → Network Access, add that egress IP and name the rule for audits:

<fly-app-name> — Fly egress (iad)

Full naming rules: Naming conventions — MongoDB Atlas IP access.

One egress IP per Fly app per tier

  • Staging egress ≠ production egress—separate Fly apps, separate Atlas rules.
  • Re-allocating egress requires updating Atlas and is a rotation event.
  • Skip egress allocation when the datastore does not use IP allowlists.
  • Staging, UAT, and production should use separate MONGODB_URI values (and often separate Atlas projects or clusters) per policy.
  • Database and cluster names should trace to the GitHub repo and tier—see Naming conventions.

MONGODB_URI and Atlas IP rules are high / medium priority on the Rotation inventory—schedules TBD. Rotating credentials requires updating Fly secrets, redeploying the API, and confirming Atlas access still matches egress.