MongORM-RS is a fast, simple, and powerful Object-Document Mapper (ODM) for MongoDB in Rust. It provides an ORM-like API to interact with MongoDB databases seamlessly.
- ORM-like API for MongoDB in Rust
- Fast and efficient interactions with MongoDB databases
- Simplified alternative for simulating relationships (Many-to-One and Many-to-Many)
- Supports selective fields with dynamic addition of elements
- Tested on MongoDB versions 4.2, 4.4, 5.0, 6.0
Run this command at root of your project
cargo add mongorm
Or, add this to your Cargo.toml
mongorm = "0.1.0"
use mongorm::prelude::*;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
pub struct Todo {
task_id: String,
title: String,
is_completed: bool
}
#[tokio::main]
async fn main() -> Result<(), mongorm::errors::Error> {
// establish connection to db
establish_connection();
// create a model
let todo_model = model!(Todo);
// perform CRUD
// CREATE
let new_todo = todo_model.create<Todo>(Todo {
task_id: 1,
title: "Learn Rust".to_owned(),
is_completed: false
});
// READ
let todos = todo_model.find(None);
// UPDATE
let _ = todo_model.findByIdAndUpdate<Todo>("...", Todo {
task_id: 1,
title: "Learn MONGODB".to_owned(),
is_completed: false
});
// DELETE
let _ = todo_model.findByIdAndDelete<Todo>("...");
}