Get up and running with MongoDB to SQLite migration in 5 minutes.
Download the latest release for your platform from the Releases page.
Extract and install:
# macOS/Linux
tar -xzf mongo-to-sqlite-*.tar.gz
sudo mv mongo-to-sqlite /usr/local/bin/
# Or place it in your preferred location
mv mongo-to-sqlite ~/.local/bin/
mongod --dbpath /path/to/data
If you don’t have existing data, create some test data:
mongosh
use testdb
db.users.insertMany([
{ name: "Alice", age: 30, email: "alice@example.com", active: true },
{ name: "Bob", age: 25, email: "bob@example.com", active: true },
{ name: "Charlie", age: 35, email: "charlie@example.com", active: false }
])
db.posts.insertMany([
{ title: "First Post", author: "Alice", content: "Hello World", tags: ["intro", "welcome"] },
{ title: "Second Post", author: "Bob", content: "Learning MongoDB", tags: ["tutorial"] }
])
mongo-to-sqlite \
--database testdb \
--all-tables \
--output testdb.db
You should see output indicating the migration progress and completion status.
sqlite3 testdb.db
-- Check the schema
.schema
-- Query users
SELECT * FROM users;
-- Query posts
SELECT * FROM posts;
-- Check counts
SELECT COUNT(*) FROM users;
SELECT COUNT(*) FROM posts;
mongo-to-sqlite \
--database mydb \
--table users \
--output users.db
# Generate schema without data
mongo-to-sqlite \
--database mydb \
--all-tables \
--schema-only \
--output preview.db
# Inspect it
sqlite3 preview.db ".schema"
mongo-to-sqlite \
--mongodb-uri "mongodb://user:pass@remote-host:27017" \
--database production \
--table important_collection \
--output backup.db
# Get your Turso credentials
turso db create my-database
turso db tokens create my-database
# Set environment variables
export TURSO_DATABASE_URL="libsql://my-database-org.turso.io"
export TURSO_AUTH_TOKEN="your-token-here"
# Run migration (output will go to Turso)
mongo-to-sqlite \
--database mydb \
--all-tables
Create a .env file:
# .env
MONGODB_URI=mongodb://localhost:27017
TURSO_DATABASE_URL=libsql://my-db.turso.io
TURSO_AUTH_TOKEN=your-token
RUST_LOG=info
Then run:
source .env
mongo-to-sqlite --database mydb --all-tables
For large collections, increase batch size for better performance:
mongo-to-sqlite \
--database mydb \
--table large_collection \
--batch-size 5000 \
--output large.db
Sample more documents for better schema accuracy:
mongo-to-sqlite \
--database mydb \
--table varied_collection \
--sample-size 500 \
--output accurate.db
Issue: Cannot connect to MongoDB
Solution: Check MongoDB is running and URI is correct
# Test MongoDB connection
mongosh mongodb://localhost:27017 --eval "db.adminCommand('ping')"
Issue: Cannot create output file
Solution: Ensure write permissions in output directory
# Create directory with proper permissions
mkdir -p output
chmod 755 output
mongo-to-sqlite --database mydb --all-tables --output output/mydb.db
Issue: Program crashes with large collections
Solution: Reduce batch size
mongo-to-sqlite \
--database mydb \
--table huge_collection \
--batch-size 100 \
--output huge.db
Now that you’ve completed your first migration:
sqlite3 <file>.db .schema to see the generated tables# Basic migration
mongo-to-sqlite --database mydb --all-tables --output mydb.db
# Single table
mongo-to-sqlite --database mydb --table users --output users.db
# Schema only
mongo-to-sqlite --database mydb --all-tables --schema-only --output schema.db
# Remote MongoDB
mongo-to-sqlite --mongodb-uri "mongodb://host:27017" --database mydb --all-tables
# Turso cloud
export TURSO_DATABASE_URL="..." TURSO_AUTH_TOKEN="..."
mongo-to-sqlite --database mydb --all-tables
# Debug mode
RUST_LOG=debug mongo-to-sqlite --database mydb --table test --output test.db