Connecting Your Database · MongoDB
MongoDB
Create a MongoDB database
You can use MongoDB Atlas (cloud) or run MongoDB locally.
Atlas (recommended)
- Sign in at cloud.mongodb.com
- Create a new project and cluster (free M0 tier is fine for development)
- Under Database Access, create a user with read/write permissions
- Under Network Access, allow your IP address
- Click Connect → Drivers and copy the connection string
Set environment variables
NEXT_PUBLIC_DB_TYPE=mongodb
NEXT_DB_MONGO_URI=mongodb+srv://user:password@cluster.mongodb.net/underpeaks?retryWrites=true&w=majority
NEXT_DB_MONGO_DB_NAME=underpeaks
Connection string format
mongodb+srv://USER:PASSWORD@CLUSTER.mongodb.net/DATABASE_NAME
Replace USER, PASSWORD, CLUSTER, and DATABASE_NAME with your values.
Special characters in your password must be URL-encoded. For example,
@becomes%40.