Skip to content

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)

  1. Sign in at cloud.mongodb.com
  1. Create a project and cluster (free M0 tier is fine for development)
  1. Under Database Access, create a user with read/write permissions
  1. Under Network Access, allow your IP
  1. 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?