MongoDB Setup
Set up MongoDB Atlas for BetterLearn. This guide covers creating a cluster, configuring access, and connecting your application.
📋 Prerequisites
- A MongoDB Atlas account (free tier works great)
- Your application code ready for connection
🚀 Step-by-Step Setup
Create MongoDB Atlas Account
Go to mongodb.com/atlas and sign up for a free account.
Create a New Project
In the Atlas dashboard, create a new project for BetterLearn.
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.
Create Database User
Go to Database Access → Add New Database User. Create a user with read/write access. Save the username and password securely.
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.
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+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/betterlearn?retryWrites=true&w=majority
Replace <username> and <password> with your actual database user credentials. URL-encode special characters in the password.
🗃️ Database Collections
BetterLearn automatically creates these collections:
| Collection | Purpose |
|---|---|
users | User profiles and settings |
quizzes | Generated quizzes |
collections | Quiz collections |
files | Uploaded file metadata |
credittransactions | Credit purchase/usage history |
generations | AI tool generation history |
libraryitems | Saved library items |
rooms | Study rooms |
sitesettings | Platform configuration |
pricingplans | Credit packages |
✅ Verify Connection
After setting up, verify the connection:
- Add
MONGODB_URIto your.env.local - Run
npm run dev - Check console for "Connected to MongoDB" message
- Sign up a test user to verify data is being saved
🔧 Troubleshooting
| Error | Solution |
|---|---|
| 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. |
Database ready! Continue to Stripe Configuration to set up payments, or Deploy to Vercel.