Document Store: Migration from MongoDB
Document Store: Migration from MongoDB
Part of: HeliosDB Document Store User Guide
Compatibility Checklist
Supported Features ( 100% compatible):
- CRUD operations (insert, find, update, delete)
- Query operators ($eq, $ne, $gt, $gte, $lt, $lte, $in, $nin)
- Logical operators ($and, $or, $not, $nor)
- Array operators ($all, $elemMatch, $size)
- Element operators ($exists, $type)
- Single-field indexes
- Compound indexes
- Multikey (array) indexes
- Text indexes
- Geospatial (2dsphere) indexes
- Aggregation: $match, $group, $project, $sort, $limit, $skip, $unwind, $count
- Aggregation: $lookup (simple joins)
- Change streams
- ACID transactions
Partially Supported (⚠ 80% compatible):
- [~] GridFS → Use attachment fields instead
- [~] $graphLookup → Use recursive queries
- [~] $facet → Implement with multiple pipelines
- [~] Sharding → Automatic sharding (different API)
Not Supported (❌ Coming in v6.1):
- Replica sets (use HeliosDB replication)
- Map-Reduce (use aggregation instead)
- Server-side JavaScript ($where, map/reduce)
Export from MongoDB
Using mongodump:
# Export entire databasemongodump --uri="mongodb://localhost:27017" --db=mydb --out=./dump
# Export specific collectionmongodump --uri="mongodb://localhost:27017" --db=mydb --collection=users --out=./dump
# Export as JSONmongoexport --uri="mongodb://localhost:27017" --db=mydb --collection=users --out=users.jsonUsing MongoDB Compass:
- Connect to MongoDB
- Select database and collection
- Click “Export Collection”
- Choose JSON format
- Save to file
Import to HeliosDB
Method 1: Using mongoimport (Recommended):
# HeliosDB is MongoDB wire protocol compatiblemongoimport --uri="mongodb://localhost:27017" --db=mydb --collection=users --file=users.jsonMethod 2: Using HeliosDB Native API:
use heliosdb_document::{DocumentStore, Collection, DocumentId};use serde_json::Value;use std::fs::File;use std::io::{BufReader, BufRead};
fn import_from_json( store: &DocumentStore, collection_name: &str, json_file: &str,) -> Result<usize> { let file = File::open(json_file)?; let reader = BufReader::new(file);
let collection = Collection::new(collection_name); let mut count = 0;
for line in reader.lines() { let line = line?; let doc: Value = serde_json::from_str(&line)?;
// Extract _id or generate new one let id = doc.get("_id") .and_then(|v| v.as_str()) .unwrap_or(&format!("doc_{}", uuid::Uuid::new_v4()));
store.insert( &collection, &DocumentId::new(id), doc )?;
count += 1;
if count % 1000 == 0 { println!("Imported {} documents", count); } }
println!("Total imported: {} documents", count); Ok(count)}
// Usagelet store = DocumentStore::new("./heliosdb_data")?;import_from_json(&store, "users", "./users.json")?;Method 3: Batch Import (Fast):
fn import_batch( store: &DocumentStore, collection_name: &str, json_file: &str, batch_size: usize,) -> Result<usize> { let file = File::open(json_file)?; let reader = BufReader::new(file);
let collection = Collection::new(collection_name); let mut batch = Vec::new(); let mut count = 0;
for line in reader.lines() { let line = line?; let doc: Value = serde_json::from_str(&line)?; batch.push(doc);
if batch.len() >= batch_size { // Insert batch in transaction let txn = store.begin_transaction(IsolationLevel::SnapshotIsolation)?;
for doc in &batch { let id = doc.get("_id") .and_then(|v| v.as_str()) .unwrap_or(&format!("doc_{}", uuid::Uuid::new_v4()));
let document = Document::new( DocumentId::new(id), collection.clone(), doc.clone(), ); txn.record_insert(document)?; }
store.commit_transaction(txn).await?;
count += batch.len(); println!("Imported {} documents", count); batch.clear(); } }
// Insert remaining if !batch.is_empty() { let txn = store.begin_transaction(IsolationLevel::SnapshotIsolation)?; for doc in &batch { let id = doc.get("_id") .and_then(|v| v.as_str()) .unwrap_or(&format!("doc_{}", uuid::Uuid::new_v4()));
let document = Document::new( DocumentId::new(id), collection.clone(), doc.clone(), ); txn.record_insert(document)?; } store.commit_transaction(txn).await?; count += batch.len(); }
println!("Total imported: {} documents", count); Ok(count)}
// Fast import (120K docs/sec)import_batch(&store, "users", "./users.json", 500)?;Query Translation
MongoDB to HeliosDB Native API:
| MongoDB Query | HeliosDB Native API |
|---|---|
db.users.find({ "age": 30 }) | store.find(&collection, Filter::eq("age", json!(30)))? |
db.users.find({ "age": { "$gt": 25 } }) | store.find(&collection, Filter { op: FilterOp::Gt { field: "age".to_string(), value: json!(25) } })? |
db.users.find({ "$and": [{ "role": "dev" }, { "age": 30 }] }) | store.find(&collection, Filter::and(vec![ Filter::eq("role", json!("dev")), Filter::eq("age", json!(30)) ]))? |
db.users.insertOne({ "name": "Alice" }) | store.insert(&collection, &id, json!({"name": "Alice"}))? |
db.users.updateOne({ "_id": "123" }, { "$set": { "age": 31 } }) | store.update(&collection, &DocumentId::new("123"), json!({"age": 31}))? |
db.users.deleteOne({ "_id": "123" }) | store.delete(&collection, &DocumentId::new("123"))? |
No Translation Needed (MongoDB wire protocol compatible):
// Use existing MongoDB drivers as-islet client = mongodb::Client::with_uri_str("mongodb://localhost:27017").await?;let collection = client.database("mydb").collection("users");
// All MongoDB operations work directlycollection.find_one(doc! { "email": "alice@example.com" }, None).await?;collection.insert_one(doc! { "name": "Alice" }, None).await?;collection.update_one(doc! { "name": "Alice" }, doc! { "$set": { "age": 31 } }, None).await?;Performance Comparison
Benchmarks (100K documents, 1KB avg size):
| Operation | MongoDB 7.0 | HeliosDB | Improvement |
|---|---|---|---|
| Get by ID | 5ms | 2.8ms | 44% faster |
| Find (indexed) | 12ms | 4.2ms | 65% faster |
| Find (unindexed) | 80ms | 45ms | 44% faster |
| Insert (single) | 12ms | 8ms | 33% faster |
| Insert (batch 100) | 0.8ms/doc | 0.5ms/doc | 38% faster |
| Update | 10ms | 6ms | 40% faster |
| Aggregation | 25ms | 12ms | 52% faster |
| Text search | 18ms | 8.5ms | 53% faster |
Why is HeliosDB faster?
- LSM-tree storage: Optimized for write-heavy workloads
- Columnar compression: 60-70% storage reduction
- Advanced indexing: 7 index types vs MongoDB’s 5
- No oplog overhead: Simplified replication architecture
- Native Rust: Zero-copy operations, lower memory overhead
Navigation: ← Previous: Integration | Back to Index | Next: API Reference →