Skip to content

Conversation

@eramongodb
Copy link
Contributor

Resolves CXX-3237 and CXX-3238 for the v1::pipeline component.

The internal::doc() API is used allow direct access to the pipeline scoped_bson document by v_noabi::(collection|database)::_aggregate() when calling mongoc_database_aggregate() with a bson_t const* pipeline argument. We can consider redefining the _aggregate() function so it builds the pipeline document using scoped_bson rather than deferring it to mongoc (which would avoid the need for this internal API), e.g. as currently done in v_noabi::collection::_watch() and client::_watch() via the basic builder API. However, this PR (initially) proposes making minimal changes to the behavior of unrelated components during the v_noabi refactor of a given component to facilitate easier scoping and review. The current arrangement also helps avoid the need for multiple intermediate temporary (view) objects (pipeline.view_array() -> scoped_bson_view() -> .bson()).

@eramongodb eramongodb requested a review from kevinAlbs November 20, 2025 17:43
@eramongodb eramongodb self-assigned this Nov 20, 2025
@eramongodb eramongodb requested a review from a team as a code owner November 20, 2025 17:43
Copy link
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 comments.

scoped_bson{R"({"x": 1, "y": 2})"},
}));

CAPTURE(input);
Copy link
Collaborator

Choose a reason for hiding this comment

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

On a failed assert, this capture prints the address:

input := 0x16f6ffef8

Suggest adding a StringMaker implementation for scoped_bson:

template <>
struct Catch::StringMaker<mongocxx::scoped_bson> {
    static std::string convert(mongocxx::scoped_bson const& b) {
        return Catch::StringMaker<bsoncxx::v1::document::view>::convert(b.view());
    }
};

Resulting in:

input := {"x": 1}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be resolved by #1514.

/// Convert to the @ref mongocxx::v1 equivalent.
///
/// @par Postconditions:
/// - `other` is in an assign-or-destroy-only state.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// - `other` is in an assign-or-destroy-only state.
/// - `this` is in an assign-or-destroy-only state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. To be resolved by #1515.


void append(bsoncxx::v1::document::view doc) {
_doc += scoped_bson{BCON_NEW(this->idx(), BCON_DOCUMENT(scoped_bson_view{doc}.bson()))};
++_count;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aside: I expect the unchecked ++_count is OK. If a caller were to append INT32_MAX stages, _doc would sooner overflow an result in an exception when appending to _doc.

@eramongodb eramongodb merged commit f1c8a96 into mongodb:master Nov 20, 2025
19 of 21 checks passed
@eramongodb eramongodb deleted the cxx-abi-v1-pipeline branch November 20, 2025 20:21
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