15

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?

5
  • Could you show a (minimal) sample of what you're trying to achieve? Commented Oct 13, 2013 at 7:34
  • 1
    Not sure about the SQlite export-to-csv since I've never tried it, but to mongoimport a csv, you'll afaik need to add --type csv to your mongoimport command (and possibly use --headerline) Commented Oct 13, 2013 at 7:55
  • 1
    Hey whaddaya know --headerline fixes the fields problem. Cheers! But I've still got to hack away table by table...no elegant export-import solution yet. Commented Oct 13, 2013 at 8:04
  • 1
    Don't know of any fully automated one, sorry. It may just be that you normally want to rebuild the data somewhat to move it to mongodb since there are no joins and you may want to make the collections more access pattern oriented. Commented Oct 13, 2013 at 8:06
  • OK. I've done a complete re-edit to better present the question in light of these comments. Commented Oct 13, 2013 at 8:31

3 Answers 3

5

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>]

Sign up to request clarification or add additional context in comments.

Comments

0

You can easily import sqlite CSV elegantly with 3T MongoChef Tool (3.2+ version).

  1. You just need to select collection
  2. Select file to import
  3. You can also unselect data which is going to import. Also many options are there.
  4. Collection imported

See how to import video

2 Comments

This is an advertisement for a paid product.
Sorry. I didn't meant to do advertisement. It was free at that time. You can check Twitter link of that time. @RobertSmith.
0

Export the data using SqlLiteBrowser and import that using MongoDB Compass

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.