Skip to content

SlashDB can get the data out of your databases like Oracle, MySQL etc., into an Excel, JSON or XML format. This article takes it further and explains how you can ingest the data into MongoDB to generate collection files.

The prerequisite for this is to have  mongo_import  tool along with your Mongo Database.

The steps to be followed to get your data from any of the databases like MySQL, Oracle etc., into MongoDB using SlashDB will be as follows :

  1. Export the data from the databases like MySQL, Oracle etc., into a JSON, CSV or TSV format using SlashDB.  As an example, the below steps show how the data is exported from a table in JSON format.
  • Go to the demo site of Slashdb here
  • There are some public databases that you can connect to. Click on Chinook. This gives the list of tables within the database Chinook.

  • Click on the table name Invoice. This will show the list of all the records in this table. Then click on JSON on the top right.

  • This will show the list of all the records in JSON format. Note the url of the page. The url of the page that shows all the records in JSON in this case is
  • The list of records in the JSON format can also be directly obtained using curl command as follows from a Linux prompt.

  • You can now generate a data file directly from the curl command by piping the output to a datafile with the below command. In this case, the output file name is invoice_output.json. This file will then have all the data records from the Invoice table in the Chinook database in JSON format.
curl > invoice_output.json

You now have your data file ready to be imported into MongoDB.

2. Using mongo_import, import the data into MongoDB.

For example, the following command would import the contents of the data from invoice_output.json file into the MongoDB collection file called invoice_mongo  in the users database running on localhost.

mongoimport --db users --collection invoice_mongo --type csv --file /opt/backups/invoice_output.json

Another example is below wherein mongoimport imports data from the file /opt/backups/mdb1-example.json into the collection contacts within the database sales on a remote MongoDB database.

mongoimport --host --port 37017 --username user --password pass --collection contacts --db sales --file /opt/backups/mdb1-example.json



Back To Top