Document Store: Quick Start
Document Store: Quick Start
Part of: HeliosDB Document Store User Guide
Quick Start (10 Minutes)
Installation
# Start HeliosDB serverheliosdb start --port 5432 --mongo-port 27017
# Or using Dockerdocker run -p 5432:5432 -p 27017:27017 heliosdb/heliosdb:latestConnect 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.mydbcollection = db.usersJavaScript (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 psqlpsql -h localhost -p 5432 -U postgres -d mydb
-- Create document tableCREATE TABLE users_doc ( id TEXT PRIMARY KEY, data JSONB NOT NULL, created_at TIMESTAMP DEFAULT NOW());
-- Insert documentINSERT 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 documentlet 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 storelet store = DocumentStore::new("./data")?;
// Insert documentlet 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 25let 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 agestore.update( &Collection::new("users"), &DocumentId::new("user1"), json!({"age": 31}))?;Delete Documents
// Delete userlet deleted = store.delete( &Collection::new("users"), &DocumentId::new("user1"))?;
println!("Deleted: {}", deleted);Navigation: ← Previous: Introduction | Back to Index | Next: CRUD Operations →