Database Migrations
Migrate your existing data from other databases to Cocobase or export your data for backup and portability.All migration operations are performed through the Cocobase Dashboard. No code required.
Overview
Cocobase supports:- Import from other databases - MongoDB, Firebase, PostgreSQL, MySQL, and more
- CSV/JSON imports - Bulk import data from files
- Export options - Backup your data in multiple formats
- Migration validation - Preview and verify before importing
- Incremental migrations - Import data in batches
Import from MongoDB
Prerequisites
Before starting the migration:- Export your MongoDB data to JSON format
- Ensure you have the correct collection structure
- Have your MongoDB connection string ready (if importing directly)
Steps
-
Access Migration Tool
- Go to your Cocobase Dashboard
- Navigate to your project
- Click Settings → Migrations
- Select Import Data
-
Choose Source
- Select MongoDB as the source database
- Choose import method:
- Direct Connection - Connect to your MongoDB instance
- File Upload - Upload exported JSON files
-
Configure Connection (Direct Connection)
- Enter MongoDB connection string
- Test connection
- Select databases and collections to import
-
Map Fields
- Review collection names (will become Cocobase collections)
- Map field types if needed
- Preview sample documents
-
Run Migration
- Choose import mode:
- Replace - Clear existing data and import
- Merge - Add to existing data
- Skip duplicates - Only import new documents
- Click Start Import
- Monitor progress in real-time
- Choose import mode:
-
Verify Data
- Check imported document counts
- Review sample documents
- Test queries and relationships
File Upload Format
If uploading JSON files, use this format:Import from Firebase
Prerequisites
- Export your Firestore data
- Have your Firebase project credentials
- Understand your Firestore collection structure
Steps
-
Export from Firebase
- In Firebase Console, go to Firestore Database
- Click Import/Export
- Export to Cloud Storage or download JSON
-
Access Cocobase Migration Tool
- Dashboard → Project → Settings → Migrations
- Select Import Data → Firebase/Firestore
-
Upload Data
- Upload exported Firestore JSON files
- Or provide Firebase Admin SDK credentials for direct import
-
Configure Import
- Map Firestore collections to Cocobase collections
- Handle subcollections (flatten or nest)
- Configure timestamp conversion
-
Import & Verify
- Start import process
- Monitor progress
- Verify document structure and counts
Firebase-Specific Considerations
- Timestamps: Firestore timestamps are automatically converted to ISO 8601 strings
- Subcollections: Can be flattened or kept as nested objects
- References: Document references become ID strings
- GeoPoints: Converted to
{ lat, lng }objects
Import from SQL Databases
Migrate from PostgreSQL, MySQL, or other SQL databases.Prerequisites
- Database connection credentials
- Schema understanding (tables → collections)
- Exported SQL dump or CSV files
Steps
-
Export SQL Data to JSON/CSV
PostgreSQL:
MySQL:
-
Access Migration Tool
- Dashboard → Settings → Migrations
- Select SQL Database or CSV Import
-
Upload Files
- Upload CSV or JSON files
- Map SQL columns to document fields
- Define data types
-
Handle Relationships
- Foreign keys become document references
- Configure relationship mapping
- Choose to denormalize or keep references
-
Import Data
- Review preview
- Start import
- Verify relationships and data integrity
SQL to NoSQL Mapping
| SQL Concept | Cocobase Equivalent |
|---|---|
| Table | Collection |
| Row | Document |
| Column | Field |
| Primary Key | id field |
| Foreign Key | Reference field (stores ID) |
| Join | Population/Denormalization |
CSV Import
Import data from CSV files.CSV Format Requirements
Steps
-
Prepare CSV File
- First row must be headers (field names)
- Use standard CSV format
- Arrays can be comma-separated in quotes
- Booleans:
true/false - Dates: ISO 8601 format
-
Upload to Cocobase
- Dashboard → Migrations → Import CSV
- Select collection name
- Upload CSV file
-
Configure Field Types
- Auto-detected types are shown
- Adjust if needed:
- String, Number, Boolean
- Date (ISO format)
- Array (comma-separated)
- Object (JSON string)
-
Import Options
- Header row: Skip first row if headers
- Delimiter: Comma, semicolon, tab
- Import mode: Replace, merge, or skip duplicates
-
Import & Verify
- Preview first 10 rows
- Click Import
- Check imported documents
Advanced CSV Features
Nested Objects:JSON Import
Import bulk data from JSON files.JSON Format
Single Collection:Steps
-
Prepare JSON File
- Valid JSON format
- Follow structure above
- Maximum 10 MB per file
-
Upload to Dashboard
- Migrations → Import JSON
- Drag and drop or select file
-
Review & Import
- Preview document count
- Check field structure
- Start import
Export Data
Export your Cocobase data for backup or migration.Export Formats
- JSON - Full document structure
- CSV - Flat structure (nested objects become columns)
- MongoDB - MongoDB-compatible JSON
- SQL - SQL INSERT statements
Steps
-
Access Export Tool
- Dashboard → Settings → Export Data
-
Select Collections
- Choose specific collections or all
- Apply filters (optional)
- Select date range (optional)
-
Choose Format
- Select export format
- Configure options:
- Include metadata (
id,createdAt, etc.) - Flatten nested objects
- Date format
- Include metadata (
-
Download
- Click Export
- Download file when ready
- Files are also emailed to you
Automated Backups
Enable automatic daily/weekly backups:- Dashboard → Settings → Backups
- Enable Automatic Backups
- Choose frequency (daily/weekly)
- Select retention period
- Backups are stored in your cloud storage
Migration Best Practices
Test with Sample Data First
Test with Sample Data First
Before migrating your entire database:
- Export a small sample (100-1000 documents)
- Test import process
- Verify data integrity and structure
- Check relationships and queries
- Then proceed with full migration
Plan for Downtime
Plan for Downtime
For production migrations:
- Schedule migration during low-traffic periods
- Enable maintenance mode
- Communicate with users
- Have rollback plan ready
- Monitor error logs
Validate Data After Import
Validate Data After Import
After migration completes:
Handle Large Datasets
Handle Large Datasets
For databases with millions of documents:
- Batch Import: Import in chunks of 10,000 documents
- Use Direct Connection: Faster than file uploads
- Disable Indexes: Temporarily disable indexes during import
- Monitor Resources: Watch memory and CPU usage
- Incremental Import: Import collections one at a time
Preserve Relationships
Preserve Relationships
When migrating relational data:
- Import parent collections first (users, categories)
- Then import dependent collections (posts, comments)
- Use consistent ID mapping
- Verify foreign key references
- Test population queries
Common Migration Scenarios
Scenario 1: MongoDB to Cocobase
Scenario 2: Firebase to Cocobase
- Firebase Console → Firestore → Export
- Download JSON export
- Cocobase Dashboard → Migrations → Firebase Import
- Upload and map collections
Scenario 3: PostgreSQL to Cocobase
Scenario 4: Spreadsheet to Cocobase
- Export Excel/Sheets to CSV
- Clean data (remove formulas, formatting)
- Upload CSV to Cocobase
- Map columns to fields
Troubleshooting
Import Fails
Problem: Import stops with error Solutions:- Check file format (valid JSON/CSV)
- Reduce file size (split into smaller files)
- Remove special characters from field names
- Verify data types match
Duplicate Documents
Problem: Same documents imported multiple times Solutions:- Use Skip duplicates mode
- Ensure unique IDs
- Clean collection before re-importing
Missing Relationships
Problem: Document references broken after import Solutions:- Import parent collections first
- Verify ID mapping
- Use population to test references
- Re-run import with correct ID mapping
Performance Issues
Problem: Import is very slow Solutions:- Use direct database connection instead of file upload
- Import in smaller batches
- Temporarily disable indexes
- Upgrade to higher plan for more resources
