How do I connect a MongoDB database?
Updated 20 August 2026·1 views
Connecting MongoDB
Use MongoDB Atlas (cloud) or run MongoDB locally.Atlas (recommended)
- Sign in at cloud.mongodb.com
- Create a 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
- Click Connect → Drivers and copy the connection string
Environment variables
\\\env
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
\\\
Special characters in your password must be URL-encoded — @ becomes %40.Was this article helpful?