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: boolWhether 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
impl MongoPipelineBuilder
Sourcepub fn match_stage(self, filter: impl Into<String>) -> Self
pub fn match_stage(self, filter: impl Into<String>) -> Self
Add a $match stage.
Sourcepub fn group(
self,
id: impl Into<String>,
accumulators: impl Into<String>,
) -> Self
pub fn group( self, id: impl Into<String>, accumulators: impl Into<String>, ) -> Self
Add a $group stage.
Sourcepub fn unwind_preserve_null(self, path: impl Into<String>) -> Self
pub fn unwind_preserve_null(self, path: impl Into<String>) -> Self
Add a $unwind stage with null preservation.
Sourcepub fn lookup(
self,
from: impl Into<String>,
local_field: impl Into<String>,
foreign_field: impl Into<String>,
as: impl Into<String>,
) -> Self
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.
Sourcepub fn add_fields(self, fields: impl Into<String>) -> Self
pub fn add_fields(self, fields: impl Into<String>) -> Self
Add a $addFields stage.
Sourcepub fn replace_root(self, new_root: impl Into<String>) -> Self
pub fn replace_root(self, new_root: impl Into<String>) -> Self
Add a $replaceRoot stage.
Sourcepub fn merge_into(self, collection: impl Into<String>) -> Self
pub fn merge_into(self, collection: impl Into<String>) -> Self
Add a $merge output stage.
Sourcepub fn merge(
self,
into: impl Into<String>,
on: Option<String>,
when_matched: Option<String>,
when_not_matched: Option<String>,
) -> Self
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.
Sourcepub fn with_disk_use(self) -> Self
pub fn with_disk_use(self) -> Self
Enable disk use for large operations.
Sourcepub fn with_batch_size(self, size: u32) -> Self
pub fn with_batch_size(self, size: u32) -> Self
Set cursor batch size.
Sourcepub fn with_max_time(self, ms: u64) -> Self
pub fn with_max_time(self, ms: u64) -> Self
Set maximum execution time.
Sourcepub fn with_comment(self, comment: impl Into<String>) -> Self
pub fn with_comment(self, comment: impl Into<String>) -> Self
Add a comment for profiling.
Sourcepub fn stage_count(&self) -> usize
pub fn stage_count(&self) -> usize
Get the number of stages.
Sourcepub fn stages(&self) -> &[PipelineStage]
pub fn stages(&self) -> &[PipelineStage]
Get the stages.
Trait Implementations§
Source§impl Clone for MongoPipelineBuilder
impl Clone for MongoPipelineBuilder
Source§fn clone(&self) -> MongoPipelineBuilder
fn clone(&self) -> MongoPipelineBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MongoPipelineBuilder
impl Debug for MongoPipelineBuilder
Source§impl Default for MongoPipelineBuilder
impl Default for MongoPipelineBuilder
Source§fn default() -> MongoPipelineBuilder
fn default() -> MongoPipelineBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for MongoPipelineBuilder
impl RefUnwindSafe for MongoPipelineBuilder
impl Send for MongoPipelineBuilder
impl Sync for MongoPipelineBuilder
impl Unpin for MongoPipelineBuilder
impl UnwindSafe for MongoPipelineBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more