pub struct SessionChangeStream<T> where
    T: DeserializeOwned + Unpin
{ /* private fields */ }
Expand description

A SessionChangeStream is a change stream that was created with a ClientSession that must be iterated using one. To iterate, use SessionChangeStream::next:

let mut cs = coll.watch_with_session(None, None, &mut session).await?;
while let Some(event) = cs.next(&mut session).await? {
    println!("{:?}", event)
}

Implementations

Returns the cached resume token that can be used to resume after the most recently returned change.

See the documentation here for more information on change stream resume tokens.

Update the type streamed values will be parsed as.

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

let mut cs = coll.watch_with_session(None, None, &mut session).await?;
while let Some(event) = cs.next(&mut session).await? {
    let id = bson::to_bson(&event.id)?;
    other_coll.insert_one_with_session(doc! { "id": id }, None, &mut session).await?;
}

Returns whether the change stream will continue to receive events.

Retrieve the next result from the change stream, if any.

Where calling next will internally loop until a change document is received, this will make at most one request and return None if the returned document batch is empty. This method should be used when storing the resume token in order to ensure the most up to date token is received, e.g.

let mut change_stream = coll.watch_with_session(None, None, &mut session).await?;
let mut resume_token = None;
while change_stream.is_alive() {
    if let Some(event) = change_stream.next_if_any(&mut session).await? {
        // process event
    }
    resume_token = change_stream.resume_token();
}

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.