MONGODB ATLAS SETUP
Comprehensive guidelines for AI-assisted development within the Editor platform
π MongoDB Atlas Setup Guide for Singularity
Complete setup guide for MongoDB Atlas with GoGrab Space project
π― Connection Details
π Security Notice: Connection credentials are stored in .env.local (never commit to git!)
To get your connection string:
- Log into MongoDB Atlas
- Go to Database > Connect > Drivers
- Copy connection string and URL-encode special characters in password
- Add to
.env.local:MONGODB_CONNECTION_STRING=<your_connection_string>
Cluster: <your-cluster>.mongodb.net
Database: singularity-dev (for development)
Username: Set in MongoDB Atlas
Password: π See .env.local
π₯ Current Issues & Solutions
1. CORS Policy Issue β
Problem: Browser blocks direct calls to MongoDB Atlas Data API
Access to XMLHttpRequest at 'https://data.mongodb-api.com/app/data-hnbqp/endpoint/data/v1/action/findOne'
from origin 'http://localhost:5400' has been blocked by CORS policy
Solution: MongoDB Atlas Data API requires proper CORS configuration or server-side proxy.
2. Browser Limitations β οΈ
Direct browser access to MongoDB Atlas Data API is not recommended for production apps due to:
- CORS restrictions
- API key exposure in client-side code
- Security vulnerabilities
β Recommended Approach: Local-First Development
Based on your MongoDB documentation, here's the best approach:
Phase 1: Local Development (Current) π
π₯ PRIORITY: IndexedDB (Local Browser Database)
π₯ BACKUP: Firebase Firestore (Real-time features)
π₯ FUTURE: MongoDB Atlas (Production scaling)
Phase 2: Production Deployment π
Use MongoDB Atlas with proper server-side integration:
- Server-side API: Express.js/Node.js backend
- MongoDB Driver: Direct connection using connection string
- Atlas App Services: MongoDB Realm for web apps
π οΈ MongoDB Atlas Configuration Steps
Step 1: Atlas App Services Setup
Go to MongoDB Atlas Console
- Visit: https://cloud.mongodb.com/
- Login with your credentials
Create Atlas App Services Application
Project: GoGrab Space Application: singularity-app Cluster: Cluster0Configure HTTPS Endpoints
- Create custom HTTPS endpoints for CRUD operations
- These endpoints don't have CORS restrictions
Step 2: VS Code MongoDB Extension (From Screenshot)
Follow the setup shown in your screenshot:
- Install MongoDB for VS Code Extension
- Connect with Connection String:
# Get your connection string from .env.local file mongodb+srv://<USERNAME>:<URL_ENCODED_PASSWORD>@<CLUSTER>.mongodb.net/ - Create Playground for testing queries
- Explore Collections and manage data
Step 3: Environment Variables
Update your environment files:
# .env.local (π NEVER commit this file!)
# Get connection string from MongoDB Atlas Dashboard
NX_MONGODB_CONNECTION_STRING=mongodb+srv://<USERNAME>:<URL_ENCODED_PASSWORD>@<CLUSTER>.mongodb.net/
NX_MONGODB_DATABASE=singularity-dev
NX_MONGODB_API_KEY=<your-atlas-api-key>
π§ Current Development Strategy
Since CORS blocks direct browser access, we're using a local-first approach:
What's Working Now β
π’ IndexedDB: Local browser database (PRIMARY)
π’ Firebase Firestore: Real-time sync (SECONDARY)
π‘ MongoDB Atlas: CORS blocked (FUTURE)
π΄ Redis: Disabled for local development
Benefits of Local-First
- Instant development: No network dependencies
- Offline capabilities: Works without internet
- Fast performance: Local database operations
- No CORS issues: Browser-native IndexedDB
- Easy debugging: Dev tools integration
π MongoDB Atlas Integration Roadmap
Option A: Atlas App Services (Recommended)
Browser App β Atlas App Services HTTPS Endpoints β MongoDB Atlas
β
No CORS issues
β
Built-in authentication
β
Real-time triggers
β
Server-side validation
Option B: Server-Side Proxy
Browser App β Your Express.js API β MongoDB Atlas
β
Full control over API
β
Custom business logic
β
Multiple database support
Option C: MongoDB Realm Web SDK
Browser App β MongoDB Realm Web SDK β MongoDB Atlas
β
Direct browser connection
β
Built-in authentication
β
Real-time sync
π§ͺ Testing Current Setup
Your app should now show these messages:
β
Browser polyfills loaded - Node.js globals available
π LOCAL-FIRST DATABASE INITIALIZATION
π¦ 1. Initializing local IndexedDB database...
β
Local database connection successful
π₯ 2. Initializing Firebase Firestore...
β
Firebase connection successful
β οΈ 3. MongoDB Atlas blocked by CORS - using local database for development
βΈοΈ 4. Redis disabled for local development
β
Database initialization complete - Local development ready!
π― Next Steps
Immediate (Working Now)
- β Continue with IndexedDB - Fully functional local development
- β Test block creation - Create and persist logic blocks locally
- β Build app features - Focus on core functionality
Future MongoDB Integration
- Atlas App Services Setup - When ready for cloud scaling
- HTTPS Endpoints - Configure custom endpoints for your app
- Data Migration - Move from IndexedDB to Atlas when needed
π Resources
π Summary
β
Fixed IndexedDB version conflicts
β
Fixed MongoDB connection string format
β
Added CORS-aware error handling
β
Disabled Redis for local development
β
Prioritized local-first development approach
Your Singularity app is now ready for rapid local development! π
The CORS errors are expected and handled gracefully. Focus on building features with the robust local IndexedDB setup, and integrate MongoDB Atlas via App Services when you're ready to scale to production.