CXX-2659 Add change_stream::next()#1594
Merged
eramongodb merged 3 commits intomongodb:masterfrom Mar 12, 2026
Merged
Conversation
kevinAlbs
approved these changes
Mar 11, 2026
Collaborator
kevinAlbs
left a comment
There was a problem hiding this comment.
Nice, LGTM with a rename to try_next.
kevinAlbs
approved these changes
Mar 12, 2026
Collaborator
kevinAlbs
left a comment
There was a problem hiding this comment.
LGTM with a documentation tweak. I am very happy to see this simplify common use of the change stream API.
| /// | ||
| /// Try to obtain the next event document. | ||
| /// | ||
| /// This function does not block: the underlying cursor is advanced only once. |
Collaborator
There was a problem hiding this comment.
Advancing the cursor may block (for up to maxAwaitTimeMS). try_next gives users an option to exit early and/or save the current resume token.
Suggested change
| /// This function does not block: the underlying cursor is advanced only once. | |
| /// This function does not block indefinitely: the underlying cursor is advanced only once. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves CXX-2659 by exposing the
advance_iterator()internal helper as a public.next()function. As suggested by CXX-2659, the function returns the event document. However, rather than throwing an exception, the return value is made an optional instead, wherecs.next().has_value()is effectively equivalent to(++iter) != cs.end(). The existing change streams iteration test case is updated to reflect this equivalence betweencs.next()and++iter, including the fact that.next()followed by.begin()does not advance the underlying cursor (the reverse order is not true).