Skip to content

Document Store: Quick Start

Document Store: Quick Start

Part of: HeliosDB Document Store User Guide

Quick Start (10 Minutes)

Installation

Terminal window
# Start HeliosDB server
heliosdb start --port 5432 --mongo-port 27017
# Or using Docker
docker run -p 5432:5432 -p 27017:27017 heliosdb/heliosdb:latest

Connect Using MongoDB Driver

Rust:

use mongodb::{Client, options::ClientOptions};
let options = ClientOptions::parse("mongodb://localhost:27017").await?;
let client = Client::with_options(options)?;
let db = client.database("mydb");
let collection = db.collection("users");

Python:

from pymongo import MongoClient
client = MongoClient("mongodb://localhost:27017")
db = client.mydb
collection = db.users

JavaScript (Node.js):

const { MongoClient } = require('mongodb');
const client = new MongoClient("mongodb://localhost:27017");
await client.connect();
const db = client.db("mydb");
const collection = db.collection("users");

Connect Using PostgreSQL

-- Via psql
psql -h localhost -p 5432 -U postgres -d mydb
-- Create document table
CREATE TABLE users_doc (
id TEXT PRIMARY KEY,
data JSONB NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
);
-- Insert document
INSERT INTO users_doc (id, data) VALUES
('user1', '{"name": "Alice", "age": 30, "email": "alice@example.com"}');

Your First Document

Via MongoDB API (Rust):

use mongodb::bson::{doc, Document};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct User {
name: String,
age: i32,
email: String,
}
// Insert document
let user = User {
name: "Alice".to_string(),
age: 30,
email: "alice@example.com".to_string(),
};
let result = collection.insert_one(user, None).await?;
println!("Inserted document with ID: {}", result.inserted_id);

Via HeliosDB Native API:

use heliosdb_document::{DocumentStore, Collection, DocumentId};
use serde_json::json;
// Open store
let store = DocumentStore::new("./data")?;
// Insert document
let doc = store.insert(
&Collection::new("users"),
&DocumentId::new("user1"),
json!({
"name": "Alice",
"age": 30,
"email": "alice@example.com"
})
)?;
println!("Created: {:?}", doc);

Query Documents

use heliosdb_document::{Filter, FilterOp};
// Find users over 25
let filter = Filter {
op: FilterOp::Gt {
field: "age".to_string(),
value: json!(25),
},
};
let users = store.find(&Collection::new("users"), filter)?;
println!("Found {} users over 25", users.len());

Update Documents

// Update age
store.update(
&Collection::new("users"),
&DocumentId::new("user1"),
json!({"age": 31})
)?;

Delete Documents

// Delete user
let deleted = store.delete(
&Collection::new("users"),
&DocumentId::new("user1")
)?;
println!("Deleted: {}", deleted);

Navigation: ← Previous: Introduction | Back to Index | Next: CRUD Operations →