MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
mongocxx::v1::change_stream Class Reference

#include <mongocxx/v1/change_stream.hpp>

Description

A MongoDB change stream.

Attention
This feature is experimental! It is not ready for use!
See also

Classes

class  iterator
 An iterator over change stream events. More...
class  options
 Options for mongocxx::v1::change_stream. More...

Public Member Functions

 change_stream (change_stream &&other) noexcept
 Move constructor.
 change_stream (change_stream const &)=delete
 This class is not copyable.
 ~change_stream ()
 Destroy this object.
iterator begin ()
 Return an iterator associated with this change stream.
iterator end () const
 Return an end iterator.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::viewget_resume_token () const
 Return the resume token for this change stream.
bsoncxx::v1::document::view next ()
 Obtain the next event document.
change_streamoperator= (change_stream &&other) noexcept
 Move constructor.
change_streamoperator= (change_stream const &)=delete
 This class is not copyable.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::viewtry_next ()
 Try to obtain the next event document.

Constructor & Destructor Documentation

◆ ~change_stream()

mongocxx::v1::change_stream::~change_stream ( )

Destroy this object.

Warning
Invalidates all associated views and iterators.

◆ change_stream() [1/2]

mongocxx::v1::change_stream::change_stream ( change_stream && other)
noexcept

Move constructor.

Postconditions:
  • other is in an assign-or-destroy-only state.

◆ change_stream() [2/2]

mongocxx::v1::change_stream::change_stream ( change_stream const & )
delete

This class is not copyable.

Member Function Documentation

◆ begin()

iterator mongocxx::v1::change_stream::begin ( )

Return an iterator associated with this change stream.

Important
All iterators associated with the same change stream object share the same state.

This function advances the underlying cursor to obtain the first available event document. The underlying cursor is only advanced at most once: consecutive calls to this->begin() do not advance the underlying cursor state. To obtain subsequent available event documents, the resulting iterator must be incremented instead.

Warning
Invalidates all views to the current event document and resume token.
Exceptions
mongocxx::v1::server_errorwhen a server-side error is encountered.

◆ end()

change_stream::iterator mongocxx::v1::change_stream::end ( ) const
inline

Return an end iterator.

Important
The end iterator has no associated change stream.

◆ get_resume_token()

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > mongocxx::v1::change_stream::get_resume_token ( ) const

Return the resume token for this change stream.

Returns
Empty document when not available.

◆ next()

bsoncxx::v1::document::view mongocxx::v1::change_stream::next ( )

Obtain the next event document.

This function blocks indefinitely: the underlying cursor is repeatedly advanced until an event document is available.

Note
Calling this->begin() after this->next() does not advance the underlying cursor state.
Warning
Invalidates all views to the current event document and resume token.
Exceptions
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.

◆ operator=() [1/2]

change_stream & mongocxx::v1::change_stream::operator= ( change_stream && other)
noexcept

Move constructor.

Postconditions:
  • other is in an assign-or-destroy-only state.

◆ operator=() [2/2]

change_stream & mongocxx::v1::change_stream::operator= ( change_stream const & )
delete

This class is not copyable.

◆ try_next()

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > mongocxx::v1::change_stream::try_next ( )

Try to obtain the next event document.

This function does not block indefinitely: the underlying cursor is advanced only once. An empty optional is returned when an event document is not available.

Note
Calling this->begin() after this->try_next() does not advance the underlying cursor state.
Warning
Invalidates all views to the current event document and resume token.
Exceptions
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.

The documentation for this class was generated from the following file: