Struct mongodb::sync::SessionChangeStream
source · [−]pub struct SessionChangeStream<T> where
T: DeserializeOwned + Unpin, { /* private fields */ }
sync
or tokio-sync
only.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)?;
while let Some(event) = cs.next(&mut session)? {
println!("{:?}", event)
}
Implementations
sourceimpl<T> SessionChangeStream<T> where
T: DeserializeOwned + Unpin + Send + Sync,
impl<T> SessionChangeStream<T> where
T: DeserializeOwned + Unpin + Send + Sync,
sourcepub fn resume_token(&self) -> Option<ResumeToken>
pub fn resume_token(&self) -> Option<ResumeToken>
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.
sourcepub fn with_type<D: DeserializeOwned + Unpin + Send + Sync>(
self
) -> SessionChangeStream<D>
pub fn with_type<D: DeserializeOwned + Unpin + Send + Sync>(
self
) -> SessionChangeStream<D>
Update the type streamed values will be parsed as.
sourcepub fn next(&mut self, session: &mut ClientSession) -> Result<Option<T>>
pub fn next(&mut self, session: &mut ClientSession) -> Result<Option<T>>
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)?;
while let Some(event) = cs.next(&mut session)? {
let id = bson::to_bson(&event.id)?;
other_coll.insert_one_with_session(doc! { "id": id }, None, &mut session)?;
}
sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Returns whether the change stream will continue to receive events.
sourcepub fn next_if_any(&mut self, session: &mut ClientSession) -> Result<Option<T>>
pub fn next_if_any(&mut self, session: &mut ClientSession) -> Result<Option<T>>
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)?;
let mut resume_token = None;
while change_stream.is_alive() {
if let Some(event) = change_stream.next_if_any(&mut session)? {
// process event
}
resume_token = change_stream.resume_token();
}
Auto Trait Implementations
impl<T> !RefUnwindSafe for SessionChangeStream<T>
impl<T> Send for SessionChangeStream<T> where
T: Send,
impl<T> Sync for SessionChangeStream<T> where
T: Sync,
impl<T> Unpin for SessionChangeStream<T>
impl<T> !UnwindSafe for SessionChangeStream<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more