Knowledge base · Studio 3T Desktop IDE

Export MongoDB to SQL in 5 steps

By Dakota Karlsson, Kirsty Burgess · Updated

In this tutorial, we’ll show you how to export your MongoDB data directly to a live SQL database using Studio 3T’s MongoDB to SQL Migration tool.

Watch the video on Vimeo

First things first

  1. Studio 3T: Make sure you have Studio 3T up and running.
  2. SQL database: Have your SQL connection details ready. This tutorial uses PostgreSQL, but Studio 3T supports migration to MySQL, Oracle, Microsoft SQL Server, and IBM DB2.

For this MongoDB to SQL migration tutorial, we’ll make use of two datasets:

  • Raleigh Durham Airport Weather History
  • Air Traffic Passenger Statistics

1 – Open SQL Migration

In Studio 3T, in the global toolbar, select MongoDB → SQL Migration:

Export MongoDB data to SQL with Studio 3T's SQL Migration tools

2 – Choose the MongoDB source connection

To connect to the MongoDB server with the collections you want to migrate, click on Click here to connect to a server.

In the Connection Manager dialog, you can either: connect to an existing MongoDB server or create a new connection, which if you’re a first-time user of Studio 3T you’ll likely need to set up a connection to MongoDB.

To create a new MongoDB connection, click the New Connection button.

Create a connection to the MongoDB database from which you want to migrate data

In the New Connection dialog, paste the connection string and click Next.

Alternatively, you can click Manually configure my connection settings to manually specify the details.

Click Save, then Connect.

3 – Choose your SQL target connection or directory

With Studio 3T, you can directly connect to a SQL server and immediately migrate data or save the migration as a SQL file path that you can run later at a convenient time.

Set SQL target as Server

To connect to a SQL Server, select Server and click on Click here to connect to a server.

Connect to the SQL server to which you want to export MongoDB data.

Similar to Step 2, this opens the SQL Connection Manager dialog.

Create a new SQL connection by clicking the New Connection button. Fill out the Server and SSH Tunnel tabs with the required details.

Click Save, then click OK.

Set SQL target as Directory

To save to a SQL file path, select Directory and choose the location of the statement file and the database type.

4 – Add export units

Now that we’ve successfully connected to both the MongoDB and SQL servers, it’s time to choose the data to export.

Click on Add export units. Each export unit corresponds to one single export of a source collection.

Here we’re going to choose the collections we want to migrate to PostgreSQL, which are:

  • Raleigh Durham Airport Weather History
  • Air Traffic Passenger Statistics

Click OK.

To generate a SQL Table Preview of the data and the SQL table(s) that will be created from the MongoDB collections, select the source collection and then click the Mappings button.

Click Mappings to generate a preview of the SQL tables and data that will be migrated from MongoDB to SQL.

Studio 3T shows the field mappings including the SQL data types:

Studio 3T's MongoDB to SQL Migration tool shows the SQL tables and data that will be exported from a MongoDB collection.

You can further configure how the MongoDB fields map to SQL tables and columns by making use of the mappings functionality.

5 – Run the export

When you’re satisfied that the data is correctly structured and maps to the right data types, then it’s time to run the export by clicking the Run migration button in the top toolbar.

Click Run migration to begin exporting data from your MongoDB collections to your SQL database.

You can track the export in the Operations pane which you’ll find in the lower-left side of Studio 3T.

When the export is complete, open the SQL database to see the imported data.

With some SQL clients and databases, the imported data may not appear immediately. Try reconnecting to the database.

Next steps

Learn more about exporting from MongoDB to SQL, incremental execution or batched exports, and how you can automate SQL migration.

For migrating in the opposite direction, take a look at the knowledge base article SQL to MongoDB Migration.

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes, including personalized advertising (“performance”), to provide you with additional functions (“functional”), and to show content from social media platforms, such as embedded videos (“social media”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in section 9 of our Privacy Policy.

Manage consent preferences