Skip to content

CXX-3204 add URI setter for server_selection_try_once #1374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2025

Conversation

kevinAlbs
Copy link
Collaborator

@kevinAlbs kevinAlbs commented Apr 7, 2025

Summary

  • Add method to mongocxx::uri to set serverSelectionTryOnce URI option.

Background & Motivation

Intended to help simplify a a workaround in Atlas Stream Processing. The workaround applies serverSelectionTryOnce=false to a URI if the option is not already specified. I expect this new setter can be used in streams after constructing the mongocxx::uri like:

auto uri = std::make_unique<mongocxx::uri>(uri);
// Set default "serverSelectionTryOnce=false" if not included in URI:
if (!uri->server_selection_try_once()) {
    uri->server_selection_try_once(false);
}

This is the first setter on mongocxx::uri. If acceptable, this pattern can be extended in the future to add setters for more URI options to resolve CXX-2146.

Rejected alternatives

A new option to mongocxx::options::client was considered but rejected. Server selection spec notes:

Multi-threaded drivers MUST NOT provide this mode.

But mongocxx::options::client is applied to both mongocxx::client and mongocxx::pool constructors.

The spec also notes:

Conflicting usages of the URI option and the symbol is an error.

A URI setter avoids possible disagreement.

@kevinAlbs kevinAlbs marked this pull request as ready for review April 7, 2025 19:56
Copy link
Contributor

@vector-of-bool vector-of-bool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kevinAlbs kevinAlbs merged commit e74e14f into mongodb:master Apr 8, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants