In short
The MongoDB on your laptop goes to sleep when you shut the lid. A live app needs a database that's always on, backed up and reachable by your deployed backend. That's what hosted databases give you.
Hosted databases like MongoDB Atlas or managed PostgreSQL run your database in the cloud with backups and security handled for you, so your live backend can connect to it.

Think of it like this
From the steel almirah to the bank vault
At home, your valuables sit in the steel almirah. It works, but if there's a fire or you're travelling, there's trouble. A bank vault is guarded, backed up and open to you from any branch. A hosted database is the bank vault for your app's data: someone else handles the security, backups and uptime.
The big ideas
What you need to know
Managed for you
MongoDB Atlas, and managed PostgreSQL from services like Neon or Supabase, run the server, updates and backups. You just connect.
Connection string
The service gives you one URL with the host, username and password. Your backend reads it from an environment variable.
Lock down access
Use a separate database user with a strong password, and restrict network access to your backend where the service allows it.
Backups and limits
Know how backups work on your plan and how much free storage you get, so a busy demo doesn't fill it up.
How it works
Connecting a hosted MongoDB
- 1
Create a cluster
Sign up for a free tier and create a cluster in a region close to your users, such as Mumbai.
- 2
Create a user
Add a database user with a generated password.
- 3
Network access
Allow your backend's IP. Some hosts don't have fixed IPs, so you may need to allow all, which makes a strong password essential.
- 4
Copy the URI
Copy the connection string and add your database name.
- 5
Set the env var
Paste it as MONGODB_URI in your backend host's settings and redeploy.
See it in code
Walk through the code
1# server/.env (local, never committed)2MONGODB_URI=mongodb+srv://notes_app:YOUR_PASSWORD@cluster0.abcde.mongodb.net/notes?retryWrites=true&w=majority3 4# server/.env.example (committed, so others know what to set)5MONGODB_URI=6JWT_SECRET=1/2mongodb+srv:// is Atlas's format. notes_app is the DB user, notes is the database name.
The same variable name locally and in production, so your code doesn't change. Only the value does.
Save yourself the pain
Common mistakes
Oops
Using your main admin account in the connection string.
Do this instead
Create a dedicated user with only the access the app needs.
Oops
Leaving the database name out of the URI and wondering where your data went.
Do this instead
Add /notes (or your name) before the ? in the URI, or the driver uses a default database like test.
Your mission
Move your notes to the cloud
Quick check
Where should the hosted database's connection string be stored for your deployed backend?
Go deeper
- 1Create a free hosted database and connect your deployed backend to it.
- 2Restrict network access and use a strong password for the database user.
- 3Keep separate databases for development and production.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.