MongoDB is good for certain tasks and certain data. But, even though it’s a NoSQL database, you’ll sometimes need to export data and get into a SQL database. In this scenario you’re left with a number of questions.

  1. How can you export your MongoDB data with minimal hassle?
  2. Is there some way you can have the data pre-defined into SQL syntax including TABLE and INSERT statements so you don’t need to manually do it?
  3. Can you somehow set up an automated pipeline for all future data exports?

The answer to those questions lies with APIs.

Part one: MongoDB API

Those lovely people at MongoDB have something called ‘mongoexport’. This is a utility that can be run from the system command line. It’ll produce JSON or CSV.

There are a host of options and commands you can run, which is detailed in the mongoexport docs quite nicely.

The TL;DR is:

  • Run mongoexport from the system command line, not the mongo shell
  • Export the data: mongoexport --db test --collection traffic --out traffic.json

That’s it! How nice and simple was that?

Part two: SQLizer API

Once you’ve navigated through the MongoDB export process, the hard part’s over. Now you need to convert JSON to SQL. That’s where the SQLizer API comes in.

The Sqlizer API is a simple REST interface that gives you programmatic access to our file conversion algorithm. The processes of converting a file with the API follows four steps:

  1. Initiate the file conversion
  2. Upload your file
  3. Monitor the conversion progress
  4. Download your converted file

See full docs for more detail.

Step 1: Initiate the file conversion

A JSON to SQL file conversion can be initiated with a POST request to and later accessed and updated at the endpoint{ID}/.

If the request is successful the server will respond with a HTTP 200 code and a JSON representation of the file conversion. The ID field is especially important as it is used in the url of all future requests for this file conversion.

Step 2: Upload your file

Once you have a file ID you can begin uploading your file data by sending POST requests to{ID}/data/.

The Sqlizer API allows you to upload your data in a single request or multiple requests. The latter is achieved by splitting the file into parts and sending each individually. Most files can be uploaded in a single request but if your file is larger than 100Mb or you have an unreliable connection an upload in multiple parts is recommended.

Check out the full API documentation for in-depth details on single and multiple requests.

Step 3: Monitor the conversion progress

Once your file upload is finalised it will be placed in a queue for processing. You can check on its progress with a GET request to{ID}/.

curl \ -H "Authorization: Bearer {API-KEY}"

You can see sample responses in full API documentation.

Step 4: Download your converted file

Once the file conversion process is complete you can download the converted file from the url specified in the returned ResultUrl parameter.

🎊 Success! 🎉

Part three: SQL file into SQL database

Now all that’s left to do is simply import/upload your new SQL file into your database. Because SQLizer has pre-defined TABLE and INSERT statements this step is simply waiting for your file to import/upload.

Automate and be done with it

With this setup you could potentially automate the entire process of exporting MongoDB data and getting it into your own database. You can even set up a large-scale pipeline with the SQLizer API, convert files en-masse.

Happy automating!

SQLizer converts files into SQL databases. With an API to help automate conversion tasks, it’s one of the best ways to transfer data between databases. Convert a file now.