Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL export to MongoDB

Tags:

I am looking to export an existing MySQL database table to seed a MongoDB database.

I would have thought this was a well trodden path, but it appears not to be, as I am coming up blank with a simple MySQLDUMP -> MongoDB JSON converter.

It won't take much effort to code up such a conversion utility.

like image 471
Alan Williamson Avatar asked Jul 05 '10 15:07

Alan Williamson


People also ask

Can I export database from MySQL?

Confirm that SQL is selected under format. Click “Go”. Type the file name and select the directory where your exported database is to be saved in the 'Save File' dialogue box on your local computer. Click “Save” and the process of exporting will start.

Is MongoDB compatible with MySQL?

In MongoDB, you don't need to define the schema while in MySQL you need to define your tables and columns. MongoDB doesn't support JOIN but MySQL supports JOIN operations. MongoDB uses JavaScript as query language while MySQL uses the Structured Query Language (SQL).

Can we replace MySQL with MongoDB?

MySQL, MS SQL Oracle and Server are nearly synonymous with RDBMS, but MongoDB is a cross-platform document-oriented and NoSQL database. At times, it can be a wise decision to replace MySQL with MongoDB. It is a nimble database that allows fast changes of cognitive framework when apps evolve.


1 Answers

There are a method that doesn't require you to use any other software than mysql and mongodb utilities. The disadvantage is that you have to go table by table, but in your case you only need to migrate one table, so it won't be painful.

I followed this tutorial. Relevant parts are:

  1. Get a CSV with your data. You can generate one with the following query in mysql.

    SELECT [fields] INTO outfile 'user.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM [table] 
  2. Finally, import the file using mongoimport. That's all
like image 184
Iván Rodríguez Torres Avatar answered Oct 02 '22 12:10

Iván Rodríguez Torres