Skip to content

v1: database (CXX-3237, CXX-3238)#1564

Merged
eramongodb merged 7 commits intomongodb:masterfrom
eramongodb:cxx-abi-v1-database
Jan 26, 2026
Merged

v1: database (CXX-3237, CXX-3238)#1564
eramongodb merged 7 commits intomongodb:masterfrom
eramongodb:cxx-abi-v1-database

Conversation

@eramongodb
Copy link
Copy Markdown
Contributor

Resolves CXX-3237 and CXX-3238 for the v1::database component and implements dependent functions in v1::client.

Similar to prior PRs, some parameter types are updated for better consistency with their ownership semantics. An incorrect const qualifier on .has_collection() inherited from v_noabi is also removed.


The most notable difference between the former v_noabi implementation and the new v1 implementation is that the std::string name; internal data member is removed in favor of calling mongoc_database_get_name(). This change requires updating some v_noabi mocked database tests to satisfy the expected call to .name() (both explicitly and internally) when the database object may not be backed by an actual mongoc_database_t object (_impl == nullptr). However, this behavior should not be observable to public API users of v_noabi::database.

Another notable change is that the v1 implementation of .has_collection() checks for error.code != 0 rather than the v_noabi implemention which checks error.domain != 0. Although I do not expect this makes any practical difference given the behavior of the mongoc library, it is a notable change consistent with the general improvements by v1 API to mongocxx's error handling behavior w.r.t. error codes and error categories.

Lastly, similar to what was done for client::watch(), the v1 implementation of database::watch() avoids the need to create an intermediate BSON document of the form {"pipeline": [...]} in favor of simply passing [...] directly and allowing mongoc to create the pipeline field instead. However, the v_noabi implementation continues to create the "pipeline" field manually for backward compatibility with existing v_noabi mocked tests. Although this is not strictly necessary as it is internally-observable-only behavior, it nevertheless keeps the changes to v_noabi test code minimal to help validate backward compatibility of the v_noabi refactor. Where permitted, the v1 implementation also tries to pass nullptr as argument for optional parameters to avoid redundant work parsing empty bson_t documents.

@eramongodb eramongodb requested a review from kevinAlbs January 23, 2026 15:33
@eramongodb eramongodb self-assigned this Jan 23, 2026
@eramongodb eramongodb requested a review from a team as a code owner January 23, 2026 15:33
Copy link
Copy Markdown
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM with minor test suggestions and possible further reuse.

Comment thread src/mongocxx/test/v1/client.cpp Outdated
auto const input = GENERATE("a", "b", "c");

database_destroy->interpose([&](mongoc_database_t* ptr) -> void {
if (ptr) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor: but I expect the if (ptr) is not needed.

Comment thread src/mongocxx/test/v1/client.cpp
Comment thread src/mongocxx/test/v1/database.cpp Outdated
REQUIRE(reply != nullptr);
REQUIRE(error != nullptr);

set_client_error(error);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
set_client_error(error);
set_server_error(error);

Minor test discrepancy. I expect this is still thrown as a server error because the reply has a "code" field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Updated as suggested.

Comment thread src/mongocxx/lib/mongocxx/v_noabi/mongocxx/database.cpp
@eramongodb eramongodb merged commit 836b9ee into mongodb:master Jan 26, 2026
19 of 20 checks passed
@eramongodb eramongodb deleted the cxx-abi-v1-database branch January 26, 2026 17:53
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.

2 participants