# MongoDB

Native MongoDB support with aggregation pipelines, change streams, Atlas Search, vector search, and CSFLE encryption.

## Overview

Prax provides first-class MongoDB support through the official Rust driver, bringing type-safe document operations while preserving MongoDB's flexible schema capabilities.

🔄

#### Change Streams

Real-time data change notifications

🔍

#### Atlas Search

Full-text and vector search

🔐

#### CSFLE

Client-side field-level encryption

## Connection Configuration

Configure your MongoDB connection in `prax.toml`. Supports standalone, replica sets, and MongoDB Atlas.

## Schema Definition

Define your document structure with embedded documents and arrays. Use `type` for embedded subdocuments.

## Aggregation Views

Create views backed by aggregation pipelines. Materialize them with `$merge` or `$out`.

## Change Streams

Watch for real-time changes to your collections. Requires a replica set or sharded cluster.

Note: Change streams require a replica set. For local development, run MongoDB with `--replSet rs0` and initialize the replica set.

## Sharding

Configure shard keys and zone sharding for horizontal scaling.

## Atlas Search

Full-text search with Lucene-powered Atlas Search. Includes fuzzy matching, highlighting, and scoring.

## Vector Search

Semantic similarity search with Atlas Vector Search for AI/ML applications.

## Document Operations

Type-safe atomic updates with MongoDB's rich update operators.

## Read Preference & Concerns

Fine-grained control over read/write distribution in replica sets.

Read Preference | Description
--- | ---
`Primary` | Read from primary only (default)
`PrimaryPreferred` | Primary if available, otherwise secondary
`Secondary` | Read from secondaries only
`SecondaryPreferred` | Secondary if available, otherwise primary
`Nearest` | Lowest latency member

## Client-Side Field Level Encryption

Encrypt sensitive fields before they leave your application with CSFLE.

## Atlas Triggers

Define database, scheduled, and authentication triggers for MongoDB Atlas.

## MongoDB Feature Support

Feature | Status | Notes
--- | --- | ---
Aggregation Pipelines | ✅ | Full stage support
Change Streams | ✅ | Real-time updates
Atlas Search | ✅ | Full-text search
Vector Search | ✅ | Atlas only
Sharding | ✅ | Hashed & range
Zone Sharding | ✅ | Geographic distribution
CSFLE | ✅ | AWS, Azure, GCP KMS
Atlas Triggers | ✅ | Database/Scheduled/Auth
Schema Inference | ✅ | Generate schema from docs