Tutorial: Using HeliosDB's MongoDB Protocol
Tutorial: Using HeliosDB’s MongoDB Protocol
Level: Intermediate | Time: 20 minutes | Version: 7.2.0
HeliosDB implements 50+ MongoDB aggregation stages and full wire protocol compatibility. Connect with mongosh, drivers, or any MongoDB client — no code changes needed.
Start with MongoDB Enabled
heliosdb-full --enable-mongodb --mongodb-port 27017Connect with mongosh
mongosh --host localhost --port 27017You’ll see:
HeliosDB MongoDB-compatible serverBasic CRUD Operations
Insert Documents
// Switch to a databaseuse myapp
// Insert a single documentdb.users.insertOne({ name: "Alice", email: "alice@example.com", age: 30, tags: ["admin", "developer"], address: { city: "Berlin", country: "DE" }})
// Insert multiple documentsdb.users.insertMany([ { name: "Bob", email: "bob@example.com", age: 25, tags: ["developer"] }, { name: "Carol", email: "carol@example.com", age: 35, tags: ["manager"] }, { name: "Dave", email: "dave@example.com", age: 28, tags: ["developer", "devops"] }])Query Documents
// Find all documentsdb.users.find()
// Find with filterdb.users.find({ age: { $gte: 30 } })
// Find with projection (select specific fields)db.users.find({ tags: "developer" }, { name: 1, email: 1, _id: 0 })
// Complex query with logical operatorsdb.users.find({ $or: [ { age: { $lt: 26 } }, { tags: "admin" } ]})
// Count documentsdb.users.countDocuments({ tags: "developer" })
// Distinct valuesdb.users.distinct("address.country")Update Documents
// Update one documentdb.users.updateOne( { name: "Alice" }, { $set: { age: 31 }, $addToSet: { tags: "lead" } })
// Update multiple documentsdb.users.updateMany( { tags: "developer" }, { $set: { department: "engineering" } })Delete Documents
// Delete one documentdb.users.deleteOne({ name: "Dave" })
// Delete matching documentsdb.users.deleteMany({ age: { $lt: 26 } })Aggregation Pipeline
HeliosDB supports 50+ aggregation stages — more than FerretDB.
Basic Aggregation
// Group by tag, count users per tagdb.users.aggregate([ { $unwind: "$tags" }, { $group: { _id: "$tags", count: { $sum: 1 } } }, { $sort: { count: -1 } }])Multi-Stage Pipeline
// Complex analytics: users per country with average agedb.users.aggregate([ { $match: { age: { $gte: 25 } } }, { $group: { _id: "$address.country", avg_age: { $avg: "$age" }, count: { $sum: 1 }, users: { $push: "$name" } }}, { $sort: { count: -1 } }, { $project: { country: "$_id", avg_age: { $round: ["$avg_age", 1] }, count: 1, users: 1, _id: 0 }}])$lookup (Join)
// Create orders collectiondb.orders.insertMany([ { user: "Alice", product: "Widget", amount: 29.99 }, { user: "Alice", product: "Gadget", amount: 49.99 }, { user: "Bob", product: "Widget", amount: 29.99 }])
// Join users with their ordersdb.users.aggregate([ { $lookup: { from: "orders", localField: "name", foreignField: "user", as: "orders" }}, { $project: { name: 1, order_count: { $size: "$orders" }, total_spent: { $sum: "$orders.amount" } }}])$facet (Multiple Aggregations in One)
db.users.aggregate([ { $facet: { "by_age": [ { $bucket: { groupBy: "$age", boundaries: [20, 25, 30, 35, 40], default: "40+", output: { count: { $sum: 1 } } }} ], "by_tag": [ { $unwind: "$tags" }, { $sortByCount: "$tags" } ], "summary": [ { $group: { _id: null, total: { $sum: 1 }, avg_age: { $avg: "$age" } }} ] }}])AI-Native Commands
These commands are unique to HeliosDB — no MongoDB server or FerretDB has them.
Vector Search
// Create a collection with embeddingsdb.articles.insertMany([ { title: "Intro to AI", content: "...", embedding: [0.1, 0.2, 0.3, 0.4] }, { title: "Database Design", content: "...", embedding: [0.5, 0.1, 0.2, 0.3] }, { title: "ML Pipelines", content: "...", embedding: [0.15, 0.25, 0.35, 0.45] }])
// Search for similar vectors (Atlas Search compatible syntax)db.runCommand({ vectorSearch: "articles", queryVector: [0.12, 0.22, 0.32, 0.42], path: "embedding", numCandidates: 100, limit: 5})Natural Language Queries
// Ask questions in plain Englishdb.runCommand({ nlQuery: "show me all users who signed up last week in Europe and haven't logged in since"})
// Returns: translated MongoDB query + SQL equivalent// In production, executes via heliosdb-nl NL2SQL engineSchema Analysis
// Get AI-powered schema optimization recommendationsdb.runCommand({ schemaAnalyze: "users" })
// Returns:// - Document count and average size// - Schema consistency score// - Normalization suggestions// - Index recommendations// - Data type optimization tipsIntelligent Index Recommendations
// Get index suggestions based on query patternsdb.runCommand({ indexRecommend: "users" })
// Returns:// - Recommended indexes from observed query patterns// - Cost-based ranking (estimated improvement per index)// - What-if simulation results// - Auto-apply option: APPLY INDEX RECOMMENDATION id (via SQL)Anomaly Detection
// Detect anomalies in collection datadb.runCommand({ aiAnomaly: "metrics", field: "response_time"})
// Returns: anomaly status, models used, z-score, thresholdsAI Engine Status
// Check all AI capabilitiesdb.runCommand({ aiStatus: 1 })
// Returns: vector_search, full_text_search, rag_pipeline,// nl2sql, anomaly_detection, ml_tiering, autonomous_agents,// embedding_providers, intelligent_indexingAdmin Commands
// Database statisticsdb.runCommand({ dbStats: 1 })
// Collection statisticsdb.runCommand({ collStats: "users" })
// Current operationsdb.runCommand({ currentOp: 1 })
// Server statusdb.runCommand({ serverStatus: 1 })
// List databasesdb.adminCommand({ listDatabases: 1 })
// List collectionsdb.runCommand({ listCollections: 1 })Transactions (Multi-Document ACID)
// Start a sessionconst session = db.getMongo().startSession()
// Start transactionsession.startTransaction()
try { const users = session.getDatabase("myapp").users const orders = session.getDatabase("myapp").orders
// Atomic multi-collection update users.updateOne( { name: "Alice" }, { $inc: { balance: -29.99 } }, { session } ) orders.insertOne( { user: "Alice", product: "Widget", amount: 29.99, date: new Date() }, { session } )
// Commit atomically session.commitTransaction()} catch (e) { session.abortTransaction() throw e}GridFS (Large File Storage)
// Store large files (>16MB) using GridFSconst bucket = new GridFSBucket(db, { bucketName: "attachments" })
// Upload (from Node.js driver)const uploadStream = bucket.openUploadStream("report.pdf", { contentType: "application/pdf", metadata: { department: "finance", year: 2026 }})
// Downloadconst downloadStream = bucket.openDownloadStreamByName("report.pdf")Migration from MongoDB
Step 1: Point Connection String
// Before (MongoDB)const uri = "mongodb://user:pass@mongodb-host:27017/myapp"
// After (HeliosDB) — just change the hostconst uri = "mongodb://user:pass@heliosdb-host:27017/myapp"Step 2: Verify
# mongosh connects the same waymongosh --host heliosdb-host --port 27017
# Test basic operationsdb.test.insertOne({ hello: "world" })db.test.find()Step 3: Use AI Features
// These work only on HeliosDB — bonus features, no code changes neededdb.runCommand({ aiStatus: 1 })db.runCommand({ vectorSearch: "collection", queryVector: [...], limit: 10 })db.runCommand({ nlQuery: "find inactive premium users" })Cross-Protocol Queries
The same data is accessible from all 14 protocols:
# Via MongoDBmongosh -c 'db.users.find({ age: { $gte: 30 } })'
# Via PostgreSQL (same data, SQL syntax)psql -c "SELECT * FROM users WHERE age >= 30"
# Via Redisredis-cli VSEARCH user_embeddings 5 0.1 0.2 0.3
# Via REST APIcurl http://localhost:8443/api/v1/tablesWhat’s Next
- Redis Protocol — 134+ Redis commands with AI extensions
- EXPLAIN Plans — 7 output formats with AI analysis
- CDC Events — Change data capture
- Security & Compliance — RBAC, tenancy, encryption