Skip to main content

Module raw_batch_cursor

Module raw_batch_cursor 

Source
Expand description

Raw batch cursor API for zero-copy document processing.

This module provides a high-performance alternative to the standard cursor API when you need direct access to server response batches without per-document deserialization overhead.

§When to Use

Use RawBatchCursor when:

  • Processing high-volume queries where deserialization is a bottleneck
  • Implementing custom batch-level logic (e.g., batch transformation, filtering)
  • Inspecting raw BSON structure without a known schema
  • Forwarding documents without modification (e.g., proxying, caching)

Use regular Cursor when:

  • Working with strongly-typed Deserialize documents
  • Iterating one document at a time
  • Deserialization overhead is acceptable for your use case

§Example

use futures::stream::StreamExt;

let mut cursor = coll.find(doc! {}).batch().await?;
while let Some(batch) = cursor.next().await {
    let batch = batch?;
    // Zero-copy access to documents in this batch
    for doc_result in batch.doc_slices()? {
        let doc = doc_result?;
        // Process raw document
    }
}

Structs§

RawBatch
A raw batch response returned by the server for a cursor getMore/find.
RawBatchCursor
Streams the results of a query, providing direct access to each batch of results.
SessionRawBatchCursor
A raw batch cursor that was created with a ClientSession and must be iterated using one.
SessionRawBatchCursorStream
A Stream type for the results of SessionRawBatchCursor. Returned from SessionRawBatchCursor::stream.