Skip to content

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:

Terminal window
# Export entire database
mongodump --uri="mongodb://localhost:27017" --db=mydb --out=./dump
# Export specific collection
mongodump --uri="mongodb://localhost:27017" --db=mydb --collection=users --out=./dump
# Export as JSON
mongoexport --uri="mongodb://localhost:27017" --db=mydb --collection=users --out=users.json

Using MongoDB Compass:

  1. Connect to MongoDB
  2. Select database and collection
  3. Click “Export Collection”
  4. Choose JSON format
  5. Save to file

Import to HeliosDB

Method 1: Using mongoimport (Recommended):

Terminal window
# HeliosDB is MongoDB wire protocol compatible
mongoimport --uri="mongodb://localhost:27017" --db=mydb --collection=users --file=users.json

Method 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)
}
// Usage
let 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 QueryHeliosDB 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-is
let client = mongodb::Client::with_uri_str("mongodb://localhost:27017").await?;
let collection = client.database("mydb").collection("users");
// All MongoDB operations work directly
collection.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):

OperationMongoDB 7.0HeliosDBImprovement
Get by ID5ms2.8ms44% faster
Find (indexed)12ms4.2ms65% faster
Find (unindexed)80ms45ms44% faster
Insert (single)12ms8ms33% faster
Insert (batch 100)0.8ms/doc0.5ms/doc38% faster
Update10ms6ms40% faster
Aggregation25ms12ms52% faster
Text search18ms8.5ms53% faster

Why is HeliosDB faster?

  1. LSM-tree storage: Optimized for write-heavy workloads
  2. Columnar compression: 60-70% storage reduction
  3. Advanced indexing: 7 index types vs MongoDB’s 5
  4. No oplog overhead: Simplified replication architecture
  5. Native Rust: Zero-copy operations, lower memory overhead


Navigation: ← Previous: Integration | Back to Index | Next: API Reference →