Documentation

SQL Migration & Task Manager

SQL Migration

Migrate data between MongoDB and SQL databases with intelligent type mapping, schema generation, and bidirectional support. Use SQL tables, views, or queries as sources for importing into MongoDB, or export MongoDB collections directly to SQL databases.

Quick Start

Set up a SQL migration in minutes:

  1. Create a new export job in Task Manager or right-click a collection
  2. Select source type (MongoDB Collection/Query) or SQL source (Table/View/Query)
  3. Select target type (SQL Table/Script) or MongoDB Collection
  4. Choose or create a SQL connection (MySQL, PostgreSQL, SQL Server, Oracle)
  5. Configure field mapping and type conversions
  6. Preview and execute the migration

SQL Source Types

Import data from SQL databases into MongoDB using these source options.

Source Type Description Use Case
SQL Table Import all rows from a SQL table Full table migration to MongoDB collection
SQL View Import from a SQL view (pre-joined/filtered data) Import denormalized data from multiple tables
SQL Query Import using custom SELECT statement Complex joins, filters, or transformations at source
Screenshot SQLM01 Source type dropdown showing SQL options: Table, SQL View, SQL Query

SQL Target Types

Export MongoDB data to SQL databases using these target options.

Target Type Description Use Case
SQL Table Export directly to a SQL database table Live migration with Insert/Upsert/DropInsert modes
SQL Script Generate SQL INSERT/UPDATE statements as a file Review before execution, version control, manual apply
Screenshot SQLM02 Target type dropdown showing SQL options: Table, SQL Script

Supported SQL Databases

VisuaLeaf supports migration to and from major relational databases.

Database Versions Features
MySQL 5.7+, 8.0+ JSON columns, SSL/TLS, connection pooling
PostgreSQL 10+, 12+, 14+, 16+ JSONB columns, array types, SSL/TLS
SQL Server 2016+, 2019+, 2022+ Windows/Linux, Azure SQL, SSL/TLS
Oracle 12c+, 19c+, 21c+ JSON columns, connection pooling
Screenshot SQLM03 SQL connection selector dropdown showing database type icons (MySQL, PostgreSQL, SQL Server, Oracle)

Type Mapping

VisuaLeaf automatically maps MongoDB types to appropriate SQL types, with manual override options.

MongoDB to SQL Type Mapping

MongoDB Type MySQL PostgreSQL SQL Server
String VARCHAR / TEXT VARCHAR / TEXT NVARCHAR / NTEXT
Number (Int) INT / BIGINT INTEGER / BIGINT INT / BIGINT
Number (Double) DOUBLE DOUBLE PRECISION FLOAT
Boolean TINYINT(1) BOOLEAN BIT
Date DATETIME TIMESTAMP DATETIME2
ObjectId CHAR(24) CHAR(24) CHAR(24)
Object / Array JSON JSONB NVARCHAR(MAX)

SQL Field Configuration

Configure SQL column properties for each mapped field.

  • Nullable - Allow NULL values in the column
  • Primary Key - Set as primary key (typically _id → id)
  • Auto Increment - Enable auto-increment for numeric primary keys
  • Unique - Add unique constraint to the column
  • Index - Create index on the column for faster queries
  • Default Value - Set default value for new rows
Screenshot SQLM04 Field mapping with SQL column config showing nullable, primary key, auto-increment, unique, index options

Write Modes

Control how data is written to the target SQL table.

Mode Behavior Use Case
Insert Insert new rows only, fail on duplicates First-time migration, append-only data
Upsert Insert new rows, update existing (by primary key) Incremental sync, keep data up-to-date
Drop & Insert Drop table, recreate schema, insert all rows Full refresh, schema changes

Data Masking

Protect sensitive data during migration by applying masking transformations. Data masking allows you to export data for development, testing, or analytics while obscuring personally identifiable information (PII) and other sensitive fields.

Masking Types

Mask Type Description Example
Redact Replace with fixed placeholder john@email.com[REDACTED]
Partial Mask Show first/last characters only john@email.comj***@***.com
Hash One-way hash (SHA-256) john@email.coma8f5f167...
Randomize Replace with random value of same type 555-1234382-9471
Fake Generate realistic fake data John SmithJane Doe
Null Replace with null/empty secret123null

Applying Masks

Apply masking in the field transformation section of your export job:

  1. Open field mapping for your export job
  2. Click on a sensitive field (email, phone, SSN, etc.)
  3. In the transformation script, use built-in masking functions
  4. Preview to verify masking is applied correctly

Masking Functions

// Redact completely
return '[REDACTED]';

// Partial mask email
return value.replace(/(.{1}).*@(.*)\.(.{2,})/, '$1***@***.$3');

// Hash value (consistent across runs)
return crypto.sha256(value);

// Randomize phone number
return '555-' + Math.floor(1000 + Math.random() * 9000);

// Null out field
return null;

Common Masking Patterns

Field Type Recommended Mask Result
Email Partial mask j***@***.com
Phone Partial mask (last 4) ***-***-1234
SSN / ID Hash or redact ***-**-6789 or hash
Credit Card Partial mask (last 4) ****-****-****-1234
Name Fake data Random realistic name
Address Fake or redact Random address or [REDACTED]
Password Null or exclude Don't export passwords
Screenshot SQLM05 Field transformation showing masking script applied to email field with preview of masked output

Pro Tips

  1. Use SQL Query source to join multiple tables before importing to MongoDB - this creates properly denormalized documents.
  2. For large migrations, use batch size control to avoid memory issues. Start with 1000 rows per batch.
  3. Generate a SQL Script first to review the SQL before executing against production databases.
  4. When exporting nested MongoDB objects to SQL, they're automatically serialized as JSON columns.
  5. Use Upsert mode for incremental syncs - it's idempotent and safe to run multiple times.
  6. Apply data masking when exporting to development/test environments to protect PII.
  7. Test your SQL connection before saving the job using the "Test Connection" button.

Ready to try VisuaLeaf?

Download and start managing your MongoDB databases with ease.

Download Free Trial