Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export database from SQLite to MongoDB

Tags:

sqlite

mongodb

What's probably the easiest way to migrate a small (< 10MB) database from SQLite to MongoDB using command line interfaces?

From what I've figured out so far it seems I'll have to do table-by-table:

> .output user.csv
> .mode csv
> .header on
> select*from user;
> .quit
> mongoimport --collection user --type csv --headerline --db rebuild user.csv

I've also done this before with a script that traversed an XML dump of an RDBMS and populated the NoSQL DB.

Both of these methods work, but they feel inelegant - surely, there's a better way to do it?

like image 767
Ben Avatar asked Oct 13 '13 07:10

Ben


People also ask

How do I export and import database into MongoDB?

Choose a file type and export location. Under Select Export File Type, select either JSON or CSV. If you select JSON, your data is exported to the target file as a comma-separated array. Then, under Output, choose where to export the file to.

How do I export SQLite database to SQL?

You can export the structure and contents to a . sql file that can be read by just about anything. File > Export > Database to SQL file. Technically, the SQLite shell is not SQLite but a console application linked to SQLite which only is a library.


Video Answer


1 Answers

If you can use NPM and node, there's an open-source tool called sqlitemongo that handles this use-case for you in a CLI interface.

Run the following terminal commands

  1. sudo npm install --global sqlitemongo

  2. sqlitemongo <sqlitepath> <mongo uri> [<mongo database>]

like image 124
Isaak Eriksson Avatar answered Oct 01 '22 03:10

Isaak Eriksson