📋 Prerequisites

  • A MongoDB Atlas account (free tier works great)
  • Your application code ready for connection

🚀 Step-by-Step Setup

1

Create MongoDB Atlas Account

Go to mongodb.com/atlas and sign up for a free account.

2

Create a New Project

In the Atlas dashboard, create a new project for BetterLearn.

3

Build a Cluster

Click "Build a Cluster". Choose the free tier (M0) for development or a paid tier for production. Select a region close to your users.

4

Create Database User

Go to Database Access → Add New Database User. Create a user with read/write access. Save the username and password securely.

5

Configure Network Access

Go to Network Access → Add IP Address. For development, you can allow access from anywhere (0.0.0.0/0). For production, whitelist specific IPs.

6

Get Connection String

Go to Database → Connect → Connect your application. Copy the connection string and replace <password> with your database user password.

🔗 Connection String Format

MONGODB_URI
mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/betterlearn?retryWrites=true&w=majority
⚠️
Important

Replace <username> and <password> with your actual database user credentials. URL-encode special characters in the password.

🗃️ Database Collections

BetterLearn automatically creates these collections:

CollectionPurpose
usersUser profiles and settings
quizzesGenerated quizzes
collectionsQuiz collections
filesUploaded file metadata
credittransactionsCredit purchase/usage history
generationsAI tool generation history
libraryitemsSaved library items
roomsStudy rooms
sitesettingsPlatform configuration
pricingplansCredit packages

✅ Verify Connection

After setting up, verify the connection:

  1. Add MONGODB_URI to your .env.local
  2. Run npm run dev
  3. Check console for "Connected to MongoDB" message
  4. Sign up a test user to verify data is being saved

🔧 Troubleshooting

ErrorSolution
Authentication failed Verify username/password. URL-encode special characters.
Network timeout Whitelist your IP in Network Access.
Invalid connection string Copy fresh string from Atlas Connect dialog.
Next Steps

Database ready! Continue to Stripe Configuration to set up payments, or Deploy to Vercel.