pub struct SessionCursor<T> { /* private fields */ }
Available on crate features sync or tokio-sync only.
Expand description

A SessionCursor is a cursor that was created with a ClientSession must be iterated using one. To iterate, retrieve a [SessionCursorIter] using SessionCursor::iter:

for doc in cursor.iter(&mut session) {
  println!("{}", doc?)
}

Implementations

Move the cursor forward, potentially triggering requests to the database for more results if the local buffer has been exhausted.

This will keep requesting data from the server until either the cursor is exhausted or batch with results in it has been received.

The return value indicates whether new results were successfully returned (true) or if the cursor has been closed (false).

Note: Cursor::current and Cursor::deserialize_current must only be called after Cursor::advance returned Ok(true). It is an error to call either of them without calling Cursor::advance first or after Cursor::advance returns an error / false.

let mut cursor = coll.find_with_session(None, None, &mut session)?;
while cursor.advance(&mut session)? {
    println!("{:?}", cursor.deserialize_current()?);
}

Returns a reference to the current result in the cursor.

Panics

Cursor::advance must return Ok(true) before Cursor::current can be invoked. Calling Cursor::current after Cursor::advance does not return true or without calling Cursor::advance at all may result in a panic.

let mut cursor = coll.find_with_session(None, None, &mut session)?;
while cursor.advance(&mut session)? {
    println!("{:?}", cursor.current());
}

Deserialize the current result to the generic type associated with this cursor.

Panics

Cursor::advance must return Ok(true) before Cursor::deserialize_current can be invoked. Calling Cursor::deserialize_current after Cursor::advance does not return true or without calling Cursor::advance at all may result in a panic.

use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Cat<'a> {
    #[serde(borrow)]
    name: &'a str
}

let coll = db.collection::<Cat>("cat");
let mut cursor = coll.find_with_session(None, None, &mut session)?;
while cursor.advance(&mut session)? {
    println!("{:?}", cursor.deserialize_current()?);
}

Retrieves a SessionCursorIter to iterate this cursor. The session provided must be the same session used to create the cursor.

Retrieve the next result from the cursor. The session provided must be the same session used to create the cursor.

Use this method when the session needs to be used again between iterations or when the added functionality of Iterator is not needed.

let mut cursor = coll.find_with_session(doc! { "x": 1 }, None, &mut session)?;
while let Some(doc) = cursor.next(&mut session).transpose()? {
    other_coll.insert_one_with_session(doc, None, &mut session)?;
}

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.