MongoDB C++ Driver  mongocxx-3.7.0
Classes | Public Member Functions | List of all members
mongocxx::change_stream Class Reference

Class representing a MongoDB change stream. More...

#include <change_stream.hpp>

Classes

class  iterator
 Class representing a MongoDB change stream iterator. More...
 

Public Member Functions

 change_stream (change_stream &&other) noexcept
 Move constructs a change_stream.
 
change_streamoperator= (change_stream &&other) noexcept
 Move assigns a change_stream.
 
 ~change_stream ()
 Destroys a change_stream.
 
iterator begin () const
 A change_stream::iterator points to the beginning of any available notifications. More...
 
iterator end () const
 A change_stream::iterator indicating stream exhaustion, meaning that no notifications are available from the stream. More...
 
bsoncxx::stdx::optional< bsoncxx::document::viewget_resume_token () const
 Returns a resume token for this change stream. More...
 

Detailed Description

Class representing a MongoDB change stream.

Member Function Documentation

◆ begin()

iterator mongocxx::change_stream::begin ( ) const

A change_stream::iterator points to the beginning of any available notifications.

Each call to begin() advances to the next available notification. The state of all iterators is tracked by the change_stream itself, so advancing one iterator advances all iterators.

change_stream::begin() and the increment operators are blocking operations. They will not return until a notification is available, the max_await_time (from the options::change_stream) milliseconds have elapsed, or a server error is encountered.

When change_stream.begin() == change_stream.end(), no notifications are available. Each call to change_stream.begin() checks again for newly-available notifications.

Returns
The change_stream::iterator
Exceptions
Throwsmongocxx::query_exception if the query failed.

◆ end()

iterator mongocxx::change_stream::end ( ) const

A change_stream::iterator indicating stream exhaustion, meaning that no notifications are available from the stream.

Returns
The change_stream::iterator indicating exhaustion

◆ get_resume_token()

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

Returns a resume token for this change stream.

If the change stream has not been iterated, and either resume_after or start_after was specified in the options to this change stream, the specified value will be returned by this method. If neither resume_after or start_after was set on the options for this change stream, and it has not been iterated, this method will return no token.

Once this change stream has been iterated, this method will return the resume token of the most recently returned document in the stream, or a postBatchResumeToken if the current batch of documents has been exhausted.

See also
https://docs.mongodb.com/manual/changeStreams/#change-stream-resume-token

The returned document::view is valid for the lifetime of the stream and its data may be updated if the change stream is iterated after this function. The value may be copied to extend its lifetime or preserve the current resume token.

Returns
The token.

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