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

    1. Create Atlas account

    2. Create a cluster

    3. Add database user

    4. Whitelist IP address

    5. 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