Database in Production
- Database in production involves setting up MongoDB Atlas and securely connecting it to a Node.js application.
- Database in Production
Why Not Local DB?
Local databases are not accessible online
Not scalable
Unsafe for production
Production Solution
Use MongoDB Atlas — a cloud-based database service.
MongoDB Atlas Setup
What is MongoDB Atlas?
MongoDB Atlas is a fully managed cloud MongoDB service.
Setup Steps
Create Atlas account
Create a cluster
Add database user
Whitelist IP address
Get connection string
Atlas Flow
Node.js App → MongoDB Atlas → Cloud Database
- Connecting Atlas with Node App
Connection Example
mongoose.connect(process.env.MONGO_URI)
.then(() => console.log("Connected to MongoDB Atlas"))
.catch(err => console.log(err));
Production Tip
Always use SRV connection string
Enable network access properly
Monitor database performance