MongoPipelineBuilder

Struct MongoPipelineBuilder 

Source
pub struct MongoPipelineBuilder {
    pub allow_disk_use: bool,
    pub batch_size: Option<u32>,
    pub max_time_ms: Option<u64>,
    pub comment: Option<String>,
    /* private fields */
}
Expand description

A builder for combining multiple MongoDB operations into a single pipeline.

This reduces round-trips by batching related operations.

§Example

use prax_query::db_optimize::MongoPipelineBuilder;

let pipeline = MongoPipelineBuilder::new()
    .match_stage(doc! { "status": "active" })
    .lookup("orders", "user_id", "_id", "user_orders")
    .unwind("$user_orders")
    .group("$user_id", doc! { "total": { "$sum": "$amount" } })
    .sort(doc! { "total": -1 })
    .limit(10)
    .build();

Fields§

§allow_disk_use: bool

Whether to allow disk use for large operations.

§batch_size: Option<u32>

Batch size for cursor.

§max_time_ms: Option<u64>

Maximum time for operation in milliseconds.

§comment: Option<String>

Comment for profiling.

Implementations§

Source§

impl MongoPipelineBuilder

Source

pub fn new() -> Self

Create a new empty pipeline builder.

Source

pub fn match_stage(self, filter: impl Into<String>) -> Self

Add a $match stage.

Source

pub fn project(self, projection: impl Into<String>) -> Self

Add a $project stage.

Source

pub fn group( self, id: impl Into<String>, accumulators: impl Into<String>, ) -> Self

Add a $group stage.

Source

pub fn sort(self, sort: impl Into<String>) -> Self

Add a $sort stage.

Source

pub fn limit(self, n: u64) -> Self

Add a $limit stage.

Source

pub fn skip(self, n: u64) -> Self

Add a $skip stage.

Source

pub fn unwind(self, path: impl Into<String>) -> Self

Add a $unwind stage.

Source

pub fn unwind_preserve_null(self, path: impl Into<String>) -> Self

Add a $unwind stage with null preservation.

Source

pub fn lookup( self, from: impl Into<String>, local_field: impl Into<String>, foreign_field: impl Into<String>, as: impl Into<String>, ) -> Self

Add a $lookup stage.

Source

pub fn add_fields(self, fields: impl Into<String>) -> Self

Add a $addFields stage.

Source

pub fn set(self, fields: impl Into<String>) -> Self

Add a $set stage.

Source

pub fn unset<I, S>(self, fields: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Add a $unset stage.

Source

pub fn replace_root(self, new_root: impl Into<String>) -> Self

Add a $replaceRoot stage.

Source

pub fn count(self, field: impl Into<String>) -> Self

Add a $count stage.

Source

pub fn sample(self, size: u64) -> Self

Add a $sample stage.

Source

pub fn merge_into(self, collection: impl Into<String>) -> Self

Add a $merge output stage.

Source

pub fn merge( self, into: impl Into<String>, on: Option<String>, when_matched: Option<String>, when_not_matched: Option<String>, ) -> Self

Add a $merge output stage with options.

Source

pub fn out(self, collection: impl Into<String>) -> Self

Add a $out stage.

Source

pub fn raw(self, stage: impl Into<String>) -> Self

Add a raw BSON stage.

Source

pub fn with_disk_use(self) -> Self

Enable disk use for large operations.

Source

pub fn with_batch_size(self, size: u32) -> Self

Set cursor batch size.

Source

pub fn with_max_time(self, ms: u64) -> Self

Set maximum execution time.

Source

pub fn with_comment(self, comment: impl Into<String>) -> Self

Add a comment for profiling.

Source

pub fn stage_count(&self) -> usize

Get the number of stages.

Source

pub fn build(&self) -> String

Build the pipeline as a JSON array string.

Source

pub fn stages(&self) -> &[PipelineStage]

Get the stages.

Trait Implementations§

Source§

impl Clone for MongoPipelineBuilder

Source§

fn clone(&self) -> MongoPipelineBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MongoPipelineBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MongoPipelineBuilder

Source§

fn default() -> MongoPipelineBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more