DevRocket
Features

Database Integration

MongoDB is a NoSQL database that is widely used for building modern applications due to its flexibility and scalability.

Setting up MongoDB Atlas

1. Create a MongoDB Cluster

Head to MongoDB Atlas and create a new project. Deploy a cluster by following the guided setup.

2. Configure Network Access

In the MongoDB Atlas dashboard:

  • Go to Network Access.
  • Click on Add IP Address.
  • Add 0.0.0.0/0 to allow access from all IPs during development.

    Note: For production, restrict access to specific IPs.

3. Get Your Connection String

Navigate to Database Access, create a database user, and copy the connection string provided by MongoDB Atlas.

4. Update Environment Variables

Rename your .env.example file to .env.local and add the following:

MONGODB_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net/<database>?retryWrites=true&w=majority

Replace <username>, <password>, and <database> with your actual database credentials.


Running Locally

1. Install MongoDB Client (Optional)

Install a MongoDB client like MongoDB Compass for visualizing and managing your database.

2. Start Your Application

Run your application locally to connect to the MongoDB Atlas cluster:

npm run start:dev

Notes

  • Use strong passwords for your database users.
  • Avoid allowing access from all IPs (0.0.0.0/0) in production.
  • Regularly monitor your cluster's performance and costs in the MongoDB Atlas dashboard.

Ready for production? Check the deployment guide for securing and optimizing your MongoDB setup.

On this page