Skip to main content

Crate prax_mongodb

Crate prax_mongodb 

Source
Expand description

§prax-mongodb

MongoDB driver for the Prax ORM with document mapping and aggregation support.

This crate provides:

  • Connection management with the official MongoDB driver
  • Built-in connection pooling
  • Document serialization/deserialization via BSON
  • Type-safe query building
  • Aggregation pipeline support
  • Change streams for real-time updates

§Example

use prax_mongodb::MongoClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a client (connection pooling is built-in)
    let client = MongoClient::builder()
        .uri("mongodb://localhost:27017")
        .database("mydb")
        .build()
        .await?;

    // Get a collection
    let users = client.collection::<User>("users");

    // Insert a document
    users.insert_one(User { name: "Alice".into(), age: 30 }).await?;

    Ok(())
}

§Document Mapping

Models can be mapped to MongoDB documents using serde:

use serde::{Deserialize, Serialize};
use prax_mongodb::ObjectId;

#[derive(Debug, Serialize, Deserialize)]
struct User {
    #[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
    id: Option<ObjectId>,
    name: String,
    email: String,
}

Re-exports§

pub use client::MongoClient;
pub use client::MongoClientBuilder;
pub use config::MongoConfig;
pub use config::MongoConfigBuilder;
pub use engine::MongoEngine;
pub use error::MongoError;
pub use error::MongoResult;
pub use filter::FilterBuilder;
pub use view::AggregationView;
pub use view::AggregationViewBuilder;
pub use view::MaterializedAggregationView;
pub use view::MergeAction;
pub use view::MergeNotMatchedAction;
pub use view::MergeOptions;

Modules§

client
MongoDB client wrapper with built-in connection pooling.
config
MongoDB connection configuration.
document
Document mapping and conversion utilities.
engine
MongoDB query engine implementation.
error
Error types for MongoDB operations.
filter
MongoDB filter/query building utilities.
prelude
Prelude for convenient imports.
types
Type conversions for MongoDB/BSON.
view
MongoDB view support using aggregation pipelines.

Macros§

doc
Construct a bson::Document value.

Structs§

Document
A BSON document represented as an associative HashMap with insertion ordering.
ObjectId
A wrapper around a raw 12-byte ObjectId.

Enums§

Bson
Possible BSON value types.