A comprehensive web application demonstrating seamless database portability between MongoDB Atlas and DataStax HCD (Hyper Converged Database) using their compatible Data APIs.
This application showcases how applications built for MongoDB can seamlessly migrate to DataStax HCD without any code changes, demonstrating true database portability through compatible Data APIs.
- π Live Database Switching: Toggle between MongoDB and HCD instantly via UI toggle
- π¦ One-Click Data Migration: Sync all MongoDB records to DataStax HCD with a single click
- π₯ User Management: Create, view, and delete user profiles
- π¨ Modern UI: Responsive Bootstrap interface with real-time database status
- π Consistent Schema: UUID-based document structure across both databases
- β‘ Real-time Operations: Instant CRUD operations with confirmation dialogs
- π Database Monitoring: Visual indicators showing active database type
- π Zero Downtime Switching: Change databases without restarting the application
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Web Interface ββββββ Database Layer ββββββ MongoDB OR β
β (Flask + UI) β β (Abstraction) β β DataStax HCD β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
- Python 3.10+
- MongoDB Atlas account OR DataStax HCD instance
- Git
git clone https://github.com/shiragannavar/MongoDB-DataStax-Compatibility-Demo.git
cd MongoDB-DataStax-Compatibility-Demopython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txtCopy .env.example to .env and configure your database:
cp .env.example .envDATABASE_TYPE=mongodb
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority
MONGODB_DATABASE=user_profilesDATABASE_TYPE=hcd
HCD_API_ENDPOINT=http://<your-hcd-endpoint>:8181
HCD_USERNAME=<your_username>
HCD_PASSWORD=<your_password>
HCD_KEYSPACE=default_keyspacepython app.pyVisit http://localhost:5001 to see the application in action!
- Visit the application at
http://localhost:5001 - Locate the toggle switch in the Database Status card
- Toggle left (unchecked): MongoDB (green badge)
- Toggle right (checked): DataStax HCD (yellow badge)
- Watch the magic: Instant database switching without restart!
When MongoDB is active, you'll see a "Sync to DataStax HCD" button:
- Ensure MongoDB is active (toggle switch left/unchecked)
- Click "Sync to DataStax HCD" button in the user list header
- Watch the sync process: Button shows spinner with "Syncing..." text
- Success notification: "Successfully synced X users to DataStax HCD"
- Switch to DataStax HCD: Toggle right to verify all data copied
- Zero Transformation: Records copied exactly as-is from MongoDB
- Duplicate Handling: Skips existing records gracefully
- Progress Feedback: Loading states and success/error notifications
- Bulk Operation: Migrates all users in a single operation
- Error Resilience: Continues sync even if individual records fail
Alternatively, you can still switch databases via configuration:
- Update
.env: ChangeDATABASE_TYPE=mongodborDATABASE_TYPE=hcd - Restart the application
- Verify the database badge updates accordingly
- Live switching: Toggle between databases in real-time
- Same interface: Identical functionality regardless of database
- Consistent data: UUID-based schema works across both databases
- Zero code changes: Same application logic for both databases
- Data migration: One-click sync from MongoDB to DataStax HCD
| Endpoint | Method | Description |
|---|---|---|
/ |
GET | Main dashboard with user list |
/create_user |
GET/POST | User creation form and handler |
/delete_user/<id> |
POST | Delete user by UUID |
/api/users |
GET | JSON API - Get all users |
/api/db_info |
GET | Current database connection info |
/api/switch_database |
POST | Switch between MongoDB and HCD |
/api/sync_to_hcd |
POST | Migrate all MongoDB records to DataStax HCD |
βββ app.py # Flask web application
βββ database.py # Database abstraction layer
βββ insert_sample_data.py # Script to generate 25 sample records
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ README.md # This file
βββ templates/ # Jinja2 HTML templates
β βββ base.html # Base layout
β βββ index.html # User dashboard
β βββ create_user.html # User creation form
βββ static/ # Frontend assets
βββ css/style.css # Custom styles with VI branding
βββ js/main.js # JavaScript functionality
The DatabaseManager class in database.py provides a unified interface:
class DatabaseManager:
def __init__(self):
self.db_type = os.getenv('DATABASE_TYPE', 'mongodb')
self._setup_connection()
def create_user(self, user_data):
# Works with both MongoDB and HCD
def get_all_users(self):
# Consistent across databases
def delete_user(self, user_id):
# Same logic, different clients
def sync_mongodb_to_hcd(self):
# One-click migration from MongoDB to DataStax HCDThe sync functionality demonstrates true database portability:
def sync_mongodb_to_hcd(self):
# Get all MongoDB records
mongodb_users = list(self.collection.find({}))
# Setup temporary HCD connection
hcd_manager = DatabaseManager()
hcd_manager.db_type = 'hcd'
hcd_manager._setup_hcd()
# Insert records without transformation
for user in mongodb_users:
hcd_manager.collection.insert_one(user)Both databases use identical document structure:
{
"_id": "550e8400-e29b-41d4-a716-446655440000",
"name": "John Doe",
"email": "[email protected]",
"age": 30,
"city": "New York",
"created_at": "2025-09-03T08:35:00.000Z"
}- Live Database Switching: Toggle between databases without restarting
- One-Click Data Migration: Sync all MongoDB records to DataStax HCD instantly
- Zero Code Changes: Same application logic works with both databases
- Visual Confirmation: UI clearly shows which database is active
- Identical Functionality: All features work exactly the same way
- Schema Consistency: UUID-based documents ensure portability
- Production Ready: Error handling, validation, and modern UI
- Sample Data: 25 realistic user records for comprehensive testing
- Backend: Python 3.10, Flask 2.3
- Database Clients: PyMongo (MongoDB), AstraPy (HCD)
- Frontend: Bootstrap 5, JavaScript ES6
- Database: MongoDB Atlas, DataStax HCD
- Deployment: Environment-based configuration
| Variable | Description | Example |
|---|---|---|
DATABASE_TYPE |
Database type (mongodb or hcd) |
mongodb |
MONGODB_URI |
MongoDB connection string | mongodb+srv://<username>:<password>@<cluster>.mongodb.net/ |
MONGODB_DATABASE |
MongoDB database name | user_profiles |
HCD_API_ENDPOINT |
HCD Data API endpoint | http://localhost:8181 |
HCD_USERNAME |
HCD username | <your_username> |
HCD_PASSWORD |
HCD password | <your_password> |
HCD_KEYSPACE |
HCD keyspace name | default_keyspace |
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -am 'Add feature' - Push to branch:
git push origin feature-name - Submit a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- MongoDB Atlas
- DataStax HCD Documentation
- [Data API Comparison Guide](https://docs.datastax.com/en/astra-db-se---
Built with β€οΈ to demonstrate the power of database portability