MongoDB Setup
For local development, you can connect to a local MongoDB instance using the connection string in the .env.local
file. For production, use MongoDB Atlas.
Follow these steps to set up MongoDB Atlas.
Step 1: Create a MongoDB Atlas Account
- Go to MongoDB Atlas and sign up for a free account.
- Once logged in, create a new project by clicking on “Create a New Project.”
Step 2: Create a Cluster
- In your new project, click on “Build a Cluster.”
- Choose the free tier (M0) for the cluster and select a cloud provider and region.
- Click on “Create Cluster” and wait for it to be provisioned (this might take a few minutes).
Step 3: Set Up Database User
- Navigate to the “Database Access” tab in MongoDB Atlas.
- Click “Add New Database User.”
- Set a username and password for your MongoDB user.
- Select “Read and Write to any database” for the user’s privileges.
- Save the user credentials.
Step 4: Allow Access from Your IP
- Go to the “Network Access” tab in MongoDB Atlas.
- Click “Add IP Address” and allow access from your current IP address (or allow access from anywhere using
0.0.0.0/0
).
Step 5: Get Your Mongo URI
- Go to the “Clusters” tab and click “Connect.”
- Choose “Connect your application.”
- Copy the provided MongoDB connection string (URI) for your cluster.
Step 6: Add the Mongo URI to .env.local
In your project’s .env.local
file, add the connection string you copied from MongoDB to MONGODB_URI
.