Overview
WhatDoc uses MongoDB as its primary database with Mongoose as the ODM (Object Data Modeling) library. The database stores user accounts, GitHub integrations, project metadata, and generated documentation.Prerequisites
- MongoDB 5.0+ (6.0+ recommended for best performance)
- 2GB+ free disk space
- Network access to MongoDB instance
Installation Options
Option 1: Local MongoDB (Development)
macOS
Ubuntu/Debian
Windows
- Download MongoDB Community Server from mongodb.com/download-center/community
- Run the installer (choose “Complete” installation)
- Install MongoDB Compass (GUI tool) when prompted
- MongoDB runs as a Windows service automatically
Option 2: MongoDB Atlas (Production)
Recommended for production deployments.- Create a free account at mongodb.com/cloud/atlas/register
- Create a new cluster (M0 free tier available)
- Configure network access:
- Click “Network Access” → “Add IP Address”
- For testing: Click “Allow Access from Anywhere” (0.0.0.0/0)
- For production: Add your server’s IP address
- Create a database user:
- Click “Database Access” → “Add New Database User”
- Choose password authentication
- Grant “Read and write to any database” role
- Get connection string:
- Click “Connect” → “Connect your application”
- Copy the connection string
- Replace
<password>with your actual password - Replace
<dbname>withwhatdoc
Option 3: Docker
Database Configuration
Connection String Format
Local MongoDB:Configure WhatDoc
Set theMONGO_URI environment variable in server/.env:
[!TIP]
For production, always use connection pooling and enable TLS/SSL. Atlas handles this automatically with mongodb+srv:// URLs.
Database Schema
WhatDoc uses two main collections:Users Collection
Collection:usersModel:
server/models/User.js
Stores user accounts and authentication data.
email(unique)githubId(for OAuth lookups)
Projects Collection
Collection:projectsModel:
server/models/Project.js
Stores documentation projects and generated content.
userId(for user project lookups)slug(unique)subdomain(unique, sparse)customDomain(unique, sparse)
modern,minimal,twilio,django,mdn,aerolatexfintech,devtools,minimalist,opensource,wikicomponentlib,consumertech,deepspace,web3,enterprise
Database Initialization
Automatic Setup
WhatDoc creates indexes and initializes the database automatically on first run:Manual Initialization
If you need to set up the database manually:Backup & Restore
Backup Database
Full backup:Restore Database
Full restore:[!WARNING] Always test restores in a non-production environment first. Restoring can overwrite existing data.
Performance Optimization
Indexing Strategy
The schema includes optimized indexes for common queries:Connection Pool Settings
For production, configure connection pooling in yourMONGO_URI:
maxPoolSize=50- Maximum concurrent connectionsminPoolSize=10- Minimum idle connectionsmaxIdleTimeMS=60000- Close idle connections after 60sretryWrites=true- Auto-retry failed writesw=majority- Write concern for data durability
Large Document Handling
ThegeneratedDocs field can contain very large Markdown content (100KB+). Consider these optimizations:
- Lazy loading: Only fetch
generatedDocswhen needed
- Compression: Enable compression in MongoDB connection
- GridFS (optional): For documents >16MB, consider GridFS:
Monitoring & Maintenance
Check Database Size
Monitor Query Performance
Index Usage Statistics
Cleanup Old Data
Remove projects older than 90 days:Security Best Practices
Enable Authentication (Production)
Network Security
- Bind to localhost only:
- Enable TLS/SSL:
- Firewall rules:
[!WARNING] Never expose MongoDB to the public internet without authentication and TLS enabled. Use MongoDB Atlas or a VPN for remote access.
Troubleshooting
Connection Refused
Authentication Failed
Slow Queries
Disk Space Issues
[!TIP] For production monitoring, use MongoDB Atlas built-in monitoring or tools like MongoDB Ops Manager, Prometheus + mongodb_exporter, or Datadog.
