From 6168b717ce52e5271a333980998b7f7d2e7c4005 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 9 Oct 2025 11:22:45 -0500 Subject: [PATCH 01/33] cpx: cxx-abi-v1-instance --- .evergreen/scripts/test.sh | 18 +- .../include/mongocxx/v1/exception.hpp | 81 ++++++- src/mongocxx/include/mongocxx/v1/instance.hpp | 122 ++++++++++- .../include/mongocxx/v1/logger-fwd.hpp | 7 +- src/mongocxx/include/mongocxx/v1/logger.hpp | 76 ++++++- .../mongocxx/v_noabi/mongocxx/instance.hpp | 83 +++---- .../mongocxx/v_noabi/mongocxx/logger-fwd.hpp | 17 +- .../mongocxx/v_noabi/mongocxx/logger.hpp | 71 +----- src/mongocxx/lib/mongocxx/v1/exception.cpp | 73 +++++++ src/mongocxx/lib/mongocxx/v1/instance.cpp | 188 ++++++++++++++++ src/mongocxx/lib/mongocxx/v1/logger.cpp | 43 ++++ .../mongocxx/v_noabi/mongocxx/instance.cpp | 145 ++++-------- .../lib/mongocxx/v_noabi/mongocxx/logger.cpp | 30 --- src/mongocxx/test/CMakeLists.txt | 21 +- src/mongocxx/test/subprocess.cpp | 190 ++++++++++++++++ src/mongocxx/test/subprocess.hh | 60 +++++ src/mongocxx/test/v1/exception.cpp | 62 ++++++ src/mongocxx/test/v1/exception.hh | 34 +++ src/mongocxx/test/v1/instance.cpp | 206 ++++++++++++++++++ src/mongocxx/test/v1/instance.hh | 32 +++ src/mongocxx/test/v1/logger.cpp | 53 +++++ src/mongocxx/test/v1/logger.hh | 37 ++++ src/mongocxx/test/v_noabi/instance.cpp | 50 +++-- src/mongocxx/test/v_noabi/logging.cpp | 28 ++- 24 files changed, 1425 insertions(+), 302 deletions(-) create mode 100644 src/mongocxx/test/subprocess.cpp create mode 100644 src/mongocxx/test/subprocess.hh create mode 100644 src/mongocxx/test/v1/exception.cpp create mode 100644 src/mongocxx/test/v1/exception.hh create mode 100644 src/mongocxx/test/v1/instance.cpp create mode 100644 src/mongocxx/test/v1/instance.hh create mode 100644 src/mongocxx/test/v1/logger.cpp create mode 100644 src/mongocxx/test/v1/logger.hh diff --git a/.evergreen/scripts/test.sh b/.evergreen/scripts/test.sh index 9edb512e40..59d8373795 100755 --- a/.evergreen/scripts/test.sh +++ b/.evergreen/scripts/test.sh @@ -289,8 +289,23 @@ else command -V valgrind valgrind --version run_test() { + valgrind_args=( + "--leak-check=full" + "--track-origins=yes" + "--num-callers=50" + "--error-exitcode=1" + "--error-limit=no" + "--read-var-info=yes" + "--suppressions=../etc/memcheck.suppressions" + ) + + # Avoid noisy diagnostics caused by deliberate subprocess termination. + if [[ "${1:?}" =~ test_instance ]]; then + valgrind_args+=("--trace-children=no") + fi + echo "Running ${1:?}..." - valgrind --leak-check=full --track-origins=yes --num-callers=50 --error-exitcode=1 --error-limit=no --read-var-info=yes --suppressions=../etc/memcheck.suppressions "${1:?}" "${test_args[@]:?}" || return + valgrind "${1:?}" "${test_args[@]:?}" || return echo "Running ${1:?}... done." } fi @@ -304,7 +319,6 @@ else run_test ./src/mongocxx/test/test_command_monitoring_specs run_test ./src/mongocxx/test/test_instance run_test ./src/mongocxx/test/test_transactions_specs - run_test ./src/mongocxx/test/test_logging run_test ./src/mongocxx/test/test_retryable_reads_specs run_test ./src/mongocxx/test/test_read_write_concern_specs run_test ./src/mongocxx/test/test_unified_format_specs diff --git a/src/mongocxx/include/mongocxx/v1/exception.hpp b/src/mongocxx/include/mongocxx/v1/exception.hpp index 25c686197e..175d1fa8ac 100644 --- a/src/mongocxx/include/mongocxx/v1/exception.hpp +++ b/src/mongocxx/include/mongocxx/v1/exception.hpp @@ -20,6 +20,13 @@ #include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -28,14 +35,60 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -enum class source_errc {}; +enum class source_errc { + zero, ///< Zero. + mongocxx, ///< From the mongocxx library. + mongoc, ///< From the mongoc library. + mongocrypt, ///< From the mongocrypt library. + server, ///< From the MongoDB server. +}; + +/// +/// The error category for @ref mongocxx::v1::source_errc. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) source_error_category(); + +/// +/// Support implicit conversion to `std::error_condition`. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +inline std::error_condition make_error_condition(source_errc code) { + return {static_cast(code), v1::source_error_category()}; +} /// /// Enumeration identifying the type (cause) of a @ref mongocxx::v1 error. /// /// @attention This feature is experimental! It is not ready for use! /// -enum class type_errc {}; +enum class type_errc { + zero, ///< Zero. + invalid_argument, ///< An invalid argument passed to the throwing function. + runtime_error, ///< An erroneous condition was detected at runtime. +}; + +/// +/// The error category for @ref mongocxx::v1::type_errc. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) type_error_category(); + +/// +/// Support implicit conversion to `std::error_condition`. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +inline std::error_condition make_error_condition(type_errc code) { + return {static_cast(code), v1::type_error_category()}; +} + +BSONCXX_PRIVATE_WARNINGS_PUSH(); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251)); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); /// /// Base class for all exceptions thrown by @ref mongocxx::v1. @@ -45,11 +98,33 @@ enum class type_errc {}; /// /// @attention This feature is experimental! It is not ready for use! /// -class exception {}; +class exception : public std::system_error { + public: + ~exception() override; + + exception(exception&&) noexcept = default; + exception& operator=(exception&&) noexcept = default; + exception(exception const&) = default; + exception& operator=(exception const&) = default; + + using std::system_error::system_error; +}; + +BSONCXX_PRIVATE_WARNINGS_POP(); } // namespace v1 } // namespace mongocxx +namespace std { + +template <> +struct is_error_condition_enum : true_type {}; + +template <> +struct is_error_condition_enum : true_type {}; + +} // namespace std + #include /// diff --git a/src/mongocxx/include/mongocxx/v1/instance.hpp b/src/mongocxx/include/mongocxx/v1/instance.hpp index 90f276f9b4..9d33d8789b 100644 --- a/src/mongocxx/include/mongocxx/v1/instance.hpp +++ b/src/mongocxx/include/mongocxx/v1/instance.hpp @@ -20,6 +20,14 @@ #include +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -50,15 +58,127 @@ namespace v1 { /// @par Special exemptions /// Only the following API are permitted to be used outside the lifetime of an instance object: /// - @ref mongocxx::v1::logger +/// - @ref mongocxx::v1::default_logger /// /// @see /// - [Initialization and Cleanup (mongoc)](https://mongoc.org/libmongoc/current/init-cleanup.html) /// -class instance {}; +class instance { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Cleanup the mongocxx (and mongoc) library. + /// + /// Calls [`mongoc_cleanup()`](https://mongoc.org/libmongoc/current/mongoc_cleanup.html). + /// + MONGOCXX_ABI_EXPORT_CDECL() ~instance(); + + /// + /// This class is not moveable. + /// + instance(instance&&) = delete; + + /// + /// This class is not moveable. + /// + instance& operator=(instance&&) = delete; + + /// + /// This class is not copyable. + /// + instance(instance const&) = delete; + + /// + /// This class is not copyable. + /// + instance& operator=(instance const&) = delete; + + /// + /// Initialize the mongoc library with unstructured log messages disabled. + /// + /// Calls [`mongoc_init()`](https://mongoc.org/libmongoc/current/mongoc_init.html) after disabling unstructured + /// log messages by calling `mongoc_log_set_handler(nullptr, nullptr)`. + /// + /// @important To use mongoc's default log message handler, construct this object with + /// @ref instance(v1::default_logger tag) instead. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` + /// object has already been created. + /// + /// @see + /// - [Custom Log Handlers (mongoc)](https://mongoc.org/libmongoc/current/unstructured_log.html#custom-log-handlers) + /// + MONGOCXX_ABI_EXPORT_CDECL() instance(); + + /// + /// Initialize the mongoc library with the custom unstructured log message handler. + /// + /// Calls [`mongoc_init`](https://mongoc.org/libmongoc/current/mongoc_init.html) after registering the custom + /// unstructured log handler by calling `mongoc_log_set_handler()`. + /// + /// @param handler Disable unstructured logging when null. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` + /// object has already been created. + /// + /// @see + /// - [Custom Log Handlers (mongoc)](https://mongoc.org/libmongoc/current/unstructured_log.html#custom-log-handlers) + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() instance(std::unique_ptr handler); + + /// + /// Initialize the mongoc library with its default unstructured log handler. + /// + /// Calls [`mongoc_init`](https://mongoc.org/libmongoc/current/mongoc_init.html) without registering any custom + /// unstructured log handler. + /// + /// @param tag Unused: only for overload resolution. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::instance::errc::multiple_instances if an `instance` + /// object has already been created. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() instance(v1::default_logger tag); + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::instance. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + multiple_instances, ///< Cannot construct multiple instance objects in a given process. + }; + + /// + /// The error category for @ref mongocxx::v1::instance::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } +}; } // namespace v1 } // namespace mongocxx +namespace std { + +template <> +struct is_error_code_enum : true_type {}; + +} // namespace std + #include /// diff --git a/src/mongocxx/include/mongocxx/v1/logger-fwd.hpp b/src/mongocxx/include/mongocxx/v1/logger-fwd.hpp index c4a155ba23..2b57d2b06a 100644 --- a/src/mongocxx/include/mongocxx/v1/logger-fwd.hpp +++ b/src/mongocxx/include/mongocxx/v1/logger-fwd.hpp @@ -16,12 +16,17 @@ #include +// + +#include + namespace mongocxx { namespace v1 { enum class log_level; -class logger; +class MONGOCXX_ABI_EXPORT logger; + class default_logger; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/logger.hpp b/src/mongocxx/include/mongocxx/v1/logger.hpp index 8f35665b92..1223114c5c 100644 --- a/src/mongocxx/include/mongocxx/v1/logger.hpp +++ b/src/mongocxx/include/mongocxx/v1/logger.hpp @@ -20,6 +20,11 @@ #include +#include +#include + +#include + namespace mongocxx { namespace v1 { @@ -28,7 +33,21 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -enum class log_level {}; +enum class log_level { + k_error, ///< MONGOC_LOG_LEVEL_ERROR + k_critical, ///< MONGOC_LOG_LEVEL_CRITICAL + k_warning, ///< MONGOC_LOG_LEVEL_WARNING + k_message, ///< MONGOC_LOG_LEVEL_MESSAGE + k_info, ///< MONGOC_LOG_LEVEL_INFO + k_debug, ///< MONGOC_LOG_LEVEL_DEBUG + k_trace, ///< MONGOC_LOG_LEVEL_TRACE +}; + +MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) to_string(log_level level); + +BSONCXX_PRIVATE_WARNINGS_PUSH(); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251)); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); /// /// The interface for an unstructured log message handler. @@ -37,7 +56,60 @@ enum class log_level {}; /// /// @attention This feature is experimental! It is not ready for use! /// -class logger {}; +class logger { + public: + /// + /// Destructor. + /// + virtual ~logger(); + + /// + /// Move constructor. + /// + logger(logger&&) = default; + + /// + /// Move assignment operator. + /// + logger& operator=(logger&&) = default; + + /// + /// Copy constructor. + /// + logger(logger const&) = default; + + /// + /// Copy assignment operator. + /// + logger& operator=(logger const&) = default; + + /// + /// Default constructor. + /// + logger() = default; + + /// + /// Handle an unstructured log message emitted by mongoc. + /// + /// Users may override this function to implement custom log message behavior such as outputting messages to a file + /// or sending messages to a remote server. + /// + /// + /// + /// @param level The log level for the message being handled. + /// @param domain The domain of the message. + /// @param message The contents of the log message. + /// + /// @see + /// - [Custom Log handlers (mongoc)](https://mongoc.org/libmongoc/current/unstructured_log.html#custom-log-handlers) + /// + virtual void operator()( + log_level level, + bsoncxx::v1::stdx::string_view domain, + bsoncxx::v1::stdx::string_view message) noexcept = 0; +}; + +BSONCXX_PRIVATE_WARNINGS_POP(); /// /// A tag type representing mongoc's default unstructured log handler. diff --git a/src/mongocxx/include/mongocxx/v_noabi/mongocxx/instance.hpp b/src/mongocxx/include/mongocxx/v_noabi/mongocxx/instance.hpp index bd99b83b86..e52ecd6c4f 100644 --- a/src/mongocxx/include/mongocxx/v_noabi/mongocxx/instance.hpp +++ b/src/mongocxx/include/mongocxx/v_noabi/mongocxx/instance.hpp @@ -14,9 +14,14 @@ #pragma once +#include + +// + +#include + #include -#include #include #include @@ -24,59 +29,7 @@ namespace mongocxx { namespace v_noabi { -/// -/// An instance of the MongoDB driver. -/// -/// The constructor and destructor initialize and shut down the driver, respectively. Therefore, an -/// instance must be created before using the driver and must remain alive until all other mongocxx -/// objects are destroyed. After the instance destructor runs, the driver may not be used. -/// -/// Exactly one instance must be created in a given program. Not constructing an instance or -/// constructing more than one instance in a program are errors, even if the multiple instances have -/// non-overlapping lifetimes. -/// -/// The following is a correct example of using an instance in a program, as the instance is kept -/// alive for as long as the driver is in use: -/// -/// \code -/// -/// #include -/// #include -/// #include -/// -/// int main() { -/// mongocxx::v_noabi::instance inst{}; -/// mongocxx::v_noabi::client conn{mongocxx::v_noabi::uri{}}; -/// ... -/// } -/// -/// \endcode -/// -/// An example of using instance incorrectly might look as follows: -/// -/// \code -/// -/// #include -/// #include -/// #include -/// -/// client get_client() { -/// mongocxx::v_noabi::instance inst{}; -/// mongocxx::v_noabi::client conn{mongocxx::v_noabi::uri{}}; -/// -/// return client; -/// } // ERROR! The instance is no longer alive after this function returns. -/// -/// int main() { -/// mongocxx::v_noabi::client conn = get_client(); -/// ... -/// } -/// -/// \endcode -/// -/// For examples of more advanced usage of instance, see -/// `examples/mongocxx/instance_management.cpp`. -/// +/// @copydoc mongocxx::v1::instance class instance { public: /// @@ -90,24 +43,37 @@ class instance { /// /// @throws mongocxx::v_noabi::logic_error if an instance already exists. /// - MONGOCXX_ABI_EXPORT_CDECL() instance(std::unique_ptr logger); + MONGOCXX_ABI_EXPORT_CDECL() instance(std::unique_ptr logger); /// /// Move constructs an instance of the driver. /// - MONGOCXX_ABI_EXPORT_CDECL() instance(instance&&) noexcept; + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() instance(instance&& other) noexcept; /// /// Move assigns an instance of the driver. /// - MONGOCXX_ABI_EXPORT_CDECL(instance&) operator=(instance&&) noexcept; + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(instance&) operator=(instance&& other) noexcept; /// /// Destroys an instance of the driver. /// MONGOCXX_ABI_EXPORT_CDECL() ~instance(); + /// + /// This class is not copyable. + /// instance(instance const&) = delete; + + /// + /// This class is not copyable. + /// instance& operator=(instance const&) = delete; /// @@ -129,3 +95,6 @@ class instance { /// @file /// Provides @ref mongocxx::v_noabi::instance. /// +/// @par Includes +/// - @ref mongocxx/v1/instance.hpp +/// diff --git a/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger-fwd.hpp b/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger-fwd.hpp index 78de780424..32c31affe9 100644 --- a/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger-fwd.hpp +++ b/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger-fwd.hpp @@ -14,23 +14,29 @@ #pragma once +#include + #include namespace mongocxx { namespace v_noabi { -enum class log_level; +using v1::log_level; + +using v1::logger; -class MONGOCXX_ABI_EXPORT logger; +using v1::default_logger; } // namespace v_noabi } // namespace mongocxx namespace mongocxx { -using ::mongocxx::v_noabi::log_level; +using v1::log_level; -using ::mongocxx::v_noabi::logger; +using v1::logger; + +using v1::default_logger; } // namespace mongocxx @@ -40,3 +46,6 @@ using ::mongocxx::v_noabi::logger; /// @file /// Declares utilities related to mongocxx logging. /// +/// @par Includes +/// - @ref mongocxx/v1/logger-fwd.hpp +/// diff --git a/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger.hpp b/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger.hpp index 90fd27e3fa..d341bd0d8a 100644 --- a/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger.hpp +++ b/src/mongocxx/include/mongocxx/v_noabi/mongocxx/logger.hpp @@ -14,83 +14,25 @@ #pragma once -#include - #include -#include +// + +#include #include namespace mongocxx { namespace v_noabi { -/// -/// The log level of a log message. -/// -enum class log_level { - k_error, ///< Log Level Error. - k_critical, ///< Log Level Critical. - k_warning, ///< Log Level Warning. - k_message, ///< Log Level Message. - k_info, ///< Log Level Info. - k_debug, ///< Log Level Debug. - k_trace, ///< Log Level Trace. -}; - -/// -/// Returns a stringification of the given log level. -/// -/// @param level -/// The type to stringify. -/// -/// @return a std::string representation of the type. -/// -MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::stdx::string_view) to_string(log_level level); - -/// -/// The interface which user-defined loggers must implement. -/// -/// @see -/// - @ref mongocxx::v_noabi::instance -/// -class logger { - public: - virtual ~logger(); - - logger(logger&&) = default; - logger& operator=(logger&&) = default; - logger(logger const&) = default; - logger& operator=(logger const&) = default; - - /// - /// Handles a log message. User defined logger implementations may do whatever they wish when - /// this is called, such as log the output to a file or send it to a remote server for analysis. - /// - /// @param level - /// The log level of the current log message - /// @param domain - /// The domain of the current log message, such as 'client' - /// @param message - /// The text of the current log message. - virtual void operator()( - log_level level, - bsoncxx::v_noabi::stdx::string_view domain, - bsoncxx::v_noabi::stdx::string_view message) noexcept = 0; - - protected: - /// - /// Default constructor - /// - logger(); -}; +using v1::to_string; } // namespace v_noabi } // namespace mongocxx namespace mongocxx { -using ::mongocxx::v_noabi::to_string; +using v1::to_string; } // namespace mongocxx @@ -100,3 +42,6 @@ using ::mongocxx::v_noabi::to_string; /// @file /// Provides utilities related to mongocxx logging. /// +/// @par Includes +/// - @ref mongocxx/v1/logger.hpp +/// diff --git a/src/mongocxx/lib/mongocxx/v1/exception.cpp b/src/mongocxx/lib/mongocxx/v1/exception.cpp index 38ad005621..29798beee2 100644 --- a/src/mongocxx/lib/mongocxx/v1/exception.cpp +++ b/src/mongocxx/lib/mongocxx/v1/exception.cpp @@ -13,3 +13,76 @@ // limitations under the License. #include + +// + +#include + +#include +#include + +namespace mongocxx { +namespace v1 { + +std::error_category const& source_error_category() { + class type final : public std::error_category { + char const* name() const noexcept override { + return "mongocxx::v1::source_errc"; + } + + std::string message(int v) const noexcept override { + using code = v1::source_errc; + + switch (static_cast(v)) { + case code::zero: + return "zero"; + case code::mongocxx: + return "mongocxx"; + case code::mongoc: + return "mongoc"; + case code::mongocrypt: + return "mongocrypt"; + case code::server: + return "server"; + default: + return std::string(this->name()) + ':' + std::to_string(v); + } + } + }; + + static bsoncxx::immortal const instance; + + return instance.value(); +} + +std::error_category const& type_error_category() { + class type final : public std::error_category { + char const* name() const noexcept override { + return "mongocxx::v1::type_errc"; + } + + std::string message(int v) const noexcept override { + using code = v1::type_errc; + + switch (static_cast(v)) { + case code::zero: + return "zero"; + case code::invalid_argument: + return "invalid argument"; + case code::runtime_error: + return "runtime error"; + default: + return std::string(this->name()) + ':' + std::to_string(v); + } + } + }; + + static bsoncxx::immortal const instance; + + return instance.value(); +} + +exception::~exception() = default; + +} // namespace v1 +} // namespace mongocxx diff --git a/src/mongocxx/lib/mongocxx/v1/instance.cpp b/src/mongocxx/lib/mongocxx/v1/instance.cpp index 82b5800947..fb0c4a2306 100644 --- a/src/mongocxx/lib/mongocxx/v1/instance.cpp +++ b/src/mongocxx/lib/mongocxx/v1/instance.cpp @@ -13,3 +13,191 @@ // limitations under the License. #include + +// + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +namespace mongocxx { +namespace v1 { + +using code = v1::instance::errc; + +static_assert(!std::is_move_constructible::value, "mongocxx::v1::instance must be non-moveable"); +static_assert(!std::is_copy_constructible::value, "mongocxx::v1::instance must be non-copyable"); + +namespace { + +// 0: no instance object has been created. +// 1: there is a single instance object. +// 2: the single instance object has been destroyed. +std::atomic_int instance_state{0}; + +void custom_log_handler( + mongoc_log_level_t log_level, + char const* domain, + char const* message, + void* user_data) noexcept { + (*static_cast(user_data))( + static_cast(log_level), + bsoncxx::v1::stdx::string_view(domain), + bsoncxx::v1::stdx::string_view(message)); +} + +} // namespace + +class instance::impl { + public: + std::unique_ptr _handler; + + ~impl() { + if (_handler) { + libmongoc::log_set_handler(nullptr, nullptr); + } + + libmongoc::cleanup(); + + instance_state.fetch_add(1, std::memory_order_release); + } + + impl(impl&&) = delete; + impl& operator=(impl&&) = delete; + impl(impl const&) = delete; + impl& operator=(impl const&) = delete; + + explicit impl(std::unique_ptr handler) : _handler{std::move(handler)} { + this->init(true); + } + + explicit impl(v1::default_logger tag) { + (void)tag; + this->init(false); + } + + private: + void init(bool set_custom_handler) { + { + int expected = 0; + + if (!instance_state.compare_exchange_strong( + expected, 1, std::memory_order_acquire, std::memory_order_relaxed)) { + throw v1::exception{code::multiple_instances}; + } + } + + if (set_custom_handler) { + if (auto ptr = _handler.get()) { + libmongoc::log_set_handler(&custom_log_handler, ptr); + } else { + libmongoc::log_set_handler(nullptr, nullptr); + } + } + + libmongoc::init(); + + { + // Avoid /Zc:__cplusplus problems with MSVC. +#pragma push_macro("STDCXX") +#undef STDCXX +#if defined(_MSVC_LANG) +#define STDCXX BSONCXX_PRIVATE_STRINGIFY(_MSVC_LANG) +#else +#define STDCXX BSONCXX_PRIVATE_STRINGIFY(__cplusplus) +#endif + + // Handshake data can only be appended once (or it will return false): this is that "once". + // Despite the name, mongoc_handshake_data_append() *prepends* the platform string. + // Use " / " to delimit handshake date for mongocxx and mongoc. + (void)libmongoc::handshake_data_append( + "mongocxx", + MONGOCXX_VERSION_STRING, + "CXX=" MONGOCXX_COMPILER_ID " " MONGOCXX_COMPILER_VERSION " stdcxx=" STDCXX " / "); + +#pragma pop_macro("STDCXX") + } + } +}; + +instance::~instance() = default; + +instance::instance() : instance{v1::default_logger{}} {} + +instance::instance(std::unique_ptr handler) : _impl{bsoncxx::make_unique(std::move(handler))} {} + +instance::instance(v1::default_logger tag) : _impl{bsoncxx::make_unique(tag)} { + (void)tag; +} + +std::error_category const& instance::error_category() { + class type final : public std::error_category { + char const* name() const noexcept override { + return "mongocxx::v1::instance"; + } + + std::string message(int v) const noexcept override { + switch (static_cast(v)) { + case code::zero: + return "zero"; + case code::multiple_instances: + return "cannot construct multiple instance objects in a given process"; + default: + return std::string(this->name()) + ':' + std::to_string(v); + } + } + + bool equivalent(int v, std::error_condition const& ec) const noexcept override { + if (ec.category() == v1::source_error_category()) { + using condition = v1::source_errc; + + auto const source = static_cast(ec.value()); + + switch (static_cast(v)) { + case code::multiple_instances: + return source == condition::mongocxx; + + case code::zero: + default: + return false; + } + } + + if (ec.category() == v1::type_error_category()) { + using condition = v1::type_errc; + + auto const type = static_cast(ec.value()); + + switch (static_cast(v)) { + case code::multiple_instances: + return type == condition::runtime_error; + + case code::zero: + default: + return false; + } + } + + return false; + } + }; + + static bsoncxx::immortal const instance; + + return instance.value(); +} + +} // namespace v1 +} // namespace mongocxx diff --git a/src/mongocxx/lib/mongocxx/v1/logger.cpp b/src/mongocxx/lib/mongocxx/v1/logger.cpp index d1a70367cd..3f297e9abb 100644 --- a/src/mongocxx/lib/mongocxx/v1/logger.cpp +++ b/src/mongocxx/lib/mongocxx/v1/logger.cpp @@ -13,3 +13,46 @@ // limitations under the License. #include + +// + +#include + +#include + +namespace mongocxx { +namespace v1 { + +static_assert(static_cast(log_level::k_error) == static_cast(MONGOC_LOG_LEVEL_ERROR), ""); +static_assert(static_cast(log_level::k_critical) == static_cast(MONGOC_LOG_LEVEL_CRITICAL), ""); +static_assert(static_cast(log_level::k_warning) == static_cast(MONGOC_LOG_LEVEL_WARNING), ""); +static_assert(static_cast(log_level::k_message) == static_cast(MONGOC_LOG_LEVEL_MESSAGE), ""); +static_assert(static_cast(log_level::k_info) == static_cast(MONGOC_LOG_LEVEL_INFO), ""); +static_assert(static_cast(log_level::k_debug) == static_cast(MONGOC_LOG_LEVEL_DEBUG), ""); +static_assert(static_cast(log_level::k_trace) == static_cast(MONGOC_LOG_LEVEL_TRACE), ""); + +bsoncxx::v1::stdx::string_view to_string(log_level level) { + switch (level) { + case log_level::k_error: + return "error"; + case log_level::k_critical: + return "critical"; + case log_level::k_warning: + return "warning"; + case log_level::k_message: + return "message"; + case log_level::k_info: + return "info"; + case log_level::k_debug: + return "debug"; + case log_level::k_trace: + return "trace"; + default: + return "unknown"; + } +} + +logger::~logger() = default; + +} // namespace v1 +} // namespace mongocxx diff --git a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/instance.cpp b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/instance.cpp index 37687ae315..1156751c2b 100644 --- a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/instance.cpp +++ b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/instance.cpp @@ -12,22 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include + +// + +#include +#include +#include #include -#include -#include +#include #include #include #include -#include #include #include -#include #include namespace mongocxx { @@ -35,130 +37,61 @@ namespace v_noabi { namespace { -log_level convert_log_level(::mongoc_log_level_t mongoc_log_level) { - switch (mongoc_log_level) { - case MONGOC_LOG_LEVEL_ERROR: - return log_level::k_error; - case MONGOC_LOG_LEVEL_CRITICAL: - return log_level::k_critical; - case MONGOC_LOG_LEVEL_WARNING: - return log_level::k_warning; - case MONGOC_LOG_LEVEL_MESSAGE: - return log_level::k_message; - case MONGOC_LOG_LEVEL_INFO: - return log_level::k_info; - case MONGOC_LOG_LEVEL_DEBUG: - return log_level::k_debug; - case MONGOC_LOG_LEVEL_TRACE: - return log_level::k_trace; - default: - MONGOCXX_PRIVATE_UNREACHABLE; - } -} +// To support mongocxx::v_noabi::instance::current(). +std::atomic current_instance{nullptr}; -void null_log_handler(::mongoc_log_level_t, char const*, char const*, void*) {} - -void user_log_handler( - ::mongoc_log_level_t mongoc_log_level, - char const* log_domain, - char const* message, - void* user_data) { - (*static_cast(user_data))( - convert_log_level(mongoc_log_level), - bsoncxx::v_noabi::stdx::string_view{log_domain}, - bsoncxx::v_noabi::stdx::string_view{message}); +// Sentinel value denoting the current instance has been destroyed. +instance* sentinel() { + alignas(instance) static unsigned char value[sizeof(instance)]; + return reinterpret_cast(value); } -// A region of memory that acts as a sentintel value indicating that an instance object is being -// destroyed. We only care about the address of this object, never its contents. -alignas(instance) unsigned char sentinel[sizeof(instance)]; - -std::atomic current_instance{nullptr}; -static_assert(std::is_standard_layout::value, "Must be standard layout"); -static_assert(std::is_trivially_destructible::value, "Must be trivially destructible"); - } // namespace class instance::impl { public: - impl(std::unique_ptr logger) : _user_logger(std::move(logger)) { - libmongoc::init(); - if (_user_logger) { - libmongoc::log_set_handler(user_log_handler, _user_logger.get()); - // The libmongoc namespace mocking system doesn't play well with varargs - // functions, so we use a bare mongoc_log call here. + v1::instance _instance; + + // mongoc does not expose the state of registered custom log handlers. A bit of indirection is needed to + // condition the informational "enabled" message even after `handler` is moved-from. + impl(std::unique_ptr&& handler, bool set_custom_handler) try : _instance{std::move(handler)} { + if (set_custom_handler) { + // Inform the user that a custom log handler has been registered. + // Cannot use `libmongoc::*` mock due to varargs. mongoc_log(MONGOC_LOG_LEVEL_INFO, "mongocxx", "libmongoc logging callback enabled"); - } else { - libmongoc::log_set_handler(null_log_handler, nullptr); } - - // Despite the name, mongoc_handshake_data_append *prepends* the platform string. - // mongoc_handshake_data_append does not add a delimitter, so include the " / " in the - // argument for consistency with the driver_name, and driver_version. - std::stringstream platform; - long stdcxx = __cplusplus; -#ifdef _MSVC_LANG - // Prefer _MSVC_LANG to report the supported C++ standard with MSVC. - // The __cplusplus macro may be incorrect. See: - // https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ - stdcxx = _MSVC_LANG; -#endif - platform << "CXX=" << MONGOCXX_COMPILER_ID << " " << MONGOCXX_COMPILER_VERSION << " " - << "stdcxx=" << stdcxx << " / "; - libmongoc::handshake_data_append("mongocxx", MONGOCXX_VERSION_STRING, platform.str().c_str()); + } catch (v1::exception const&) { + throw v_noabi::logic_error{error_code::k_cannot_recreate_instance}; } - ~impl() { - // If we had a user logger, remove it so that it can't be used by the driver after it goes - // out of scope - if (_user_logger) { - libmongoc::log_set_handler(null_log_handler, nullptr); - } - - libmongoc::cleanup(); - } - - impl(impl&&) noexcept = delete; - impl& operator=(impl&&) noexcept = delete; - - impl(impl const&) = delete; - impl& operator=(impl const&) = delete; - - std::unique_ptr const _user_logger; + explicit impl(std::unique_ptr handler) : impl{std::move(handler), static_cast(handler)} {} }; instance::instance() : instance(nullptr) {} -instance::instance(std::unique_ptr logger) { - instance* expected = nullptr; - - if (!current_instance.compare_exchange_strong(expected, this)) { - throw logic_error{error_code::k_cannot_recreate_instance}; - } - - _impl = bsoncxx::make_unique(std::move(logger)); +instance::instance(std::unique_ptr logger) : _impl{bsoncxx::make_unique(std::move(logger))} { + current_instance.store(this, std::memory_order_relaxed); } -instance::instance(instance&&) noexcept = default; -instance& instance::operator=(instance&&) noexcept = default; +instance::instance(instance&& other) noexcept = default; +instance& instance::operator=(instance&& other) noexcept = default; instance::~instance() { - current_instance.store(reinterpret_cast(&sentinel)); - _impl.reset(); + current_instance.store(sentinel(), std::memory_order_relaxed); } instance& instance::current() { - if (!current_instance.load()) { - static instance the_instance; - } - - instance* curr = current_instance.load(); + if (auto const p = current_instance.load(std::memory_order_relaxed)) { + if (p == sentinel()) { + throw v_noabi::logic_error{error_code::k_instance_destroyed}; + } else { + return *p; + } - if (curr == reinterpret_cast(&sentinel)) { - throw logic_error{error_code::k_instance_destroyed}; + } else { + static instance the_instance; + return the_instance; } - - return *curr; } } // namespace v_noabi diff --git a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/logger.cpp b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/logger.cpp index 69fbc72912..ec4c30f0a5 100644 --- a/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/logger.cpp +++ b/src/mongocxx/lib/mongocxx/v_noabi/mongocxx/logger.cpp @@ -13,33 +13,3 @@ // limitations under the License. #include - -namespace mongocxx { -namespace v_noabi { - -bsoncxx::v_noabi::stdx::string_view to_string(log_level level) { - switch (level) { - case log_level::k_error: - return "error"; - case log_level::k_critical: - return "critical"; - case log_level::k_warning: - return "warning"; - case log_level::k_message: - return "message"; - case log_level::k_info: - return "info"; - case log_level::k_debug: - return "debug"; - case log_level::k_trace: - return "trace"; - default: - return "unknown"; - } -} - -logger::logger() = default; -logger::~logger() = default; - -} // namespace v_noabi -} // namespace mongocxx diff --git a/src/mongocxx/test/CMakeLists.txt b/src/mongocxx/test/CMakeLists.txt index ace3575102..abc5bf1e61 100644 --- a/src/mongocxx/test/CMakeLists.txt +++ b/src/mongocxx/test/CMakeLists.txt @@ -94,6 +94,11 @@ set(mongocxx_test_sources_v_noabi v_noabi/write_concern.cpp ) +set(mongocxx_test_sources_v1 + v1/exception.cpp + v1/logger.cpp +) + set(mongocxx_test_sources_spec spec/monitoring.cpp spec/operation.cpp @@ -113,10 +118,12 @@ set(mongocxx_test_sources_extra spec/transactions.cpp spec/unified_tests/operations.cpp spec/unified_tests/runner.cpp + subprocess.cpp v_noabi/catch_helpers.cpp v_noabi/client_helpers.cpp v_noabi/instance.cpp v_noabi/logging.cpp + v1/instance.cpp ) file(GLOB_RECURSE mongocxx_test_headers @@ -132,14 +139,17 @@ add_library(spec_test_common OBJECT ${mongocxx_test_sources_spec}) add_executable(test_driver ${mongocxx_test_sources_private} ${mongocxx_test_sources_v_noabi} + ${mongocxx_test_sources_v1} v_noabi/catch_helpers.cpp ) target_link_libraries(test_driver PRIVATE spec_test_common client_helpers) -add_executable(test_logging v_noabi/logging.cpp) -target_compile_definitions(test_logging PRIVATE MONGOCXX_TEST_DISABLE_MAIN_INSTANCE) - -add_executable(test_instance v_noabi/instance.cpp) +add_executable(test_instance + subprocess.cpp + v_noabi/instance.cpp + v_noabi/logging.cpp + v1/instance.cpp +) target_compile_definitions(test_instance PRIVATE MONGOCXX_TEST_DISABLE_MAIN_INSTANCE) add_executable(test_crud_specs spec/crud.cpp) @@ -202,7 +212,6 @@ set_property( test_driver test_gridfs_specs test_instance - test_logging test_read_write_concern_specs test_retryable_reads_specs test_transactions_specs @@ -231,7 +240,6 @@ foreach(test_name driver gridfs_specs instance - logging read_write_concern_specs retryable_reads_specs transactions_specs @@ -338,6 +346,7 @@ set_dist_list(src_mongocxx_test_DIST CMakeLists.txt ${mongocxx_test_sources_private} ${mongocxx_test_sources_v_noabi} + ${mongocxx_test_sources_v1} ${mongocxx_test_sources_spec} ${mongocxx_test_sources_extra} ${mongocxx_test_headers} diff --git a/src/mongocxx/test/subprocess.cpp b/src/mongocxx/test/subprocess.cpp new file mode 100644 index 0000000000..7c6f30ed75 --- /dev/null +++ b/src/mongocxx/test/subprocess.cpp @@ -0,0 +1,190 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +// + +#include +#include +#include + +#include + +#if !defined(_MSC_VER) + +#include // exit(), strsignal(), etc. +#include // strsignal() +#include // fork(), close(), etc. + +#include +#include // waitpid() + +namespace mongocxx { +namespace test { + +int subprocess(std::function fn, bool* is_signal_ptr) { + auto is_signal_local = false; + auto& is_signal = is_signal_ptr ? *is_signal_ptr : is_signal_local; + + pid_t const pid = ::fork(); + + // Child: do nothing more than call `fn`. + if (pid == 0) { + // Use `std::_Exit()` and `std::terminate()` to prevent continued execution of the Catch2 test suite. + try { + fn(); + std::_Exit(EXIT_SUCCESS); + } catch (Catch::TestFailureException) { + // Assertion failure already output its diagnostic message. + std::_Exit(EXIT_FAILURE); + } catch (Catch::TestSkipException) { + // SKIP() already output its diagnostic message. + // Don't try to propagate the "skip", just treat as equivalent to success. + std::_Exit(EXIT_SUCCESS); + } catch (std::exception const& ex) { + // Trigger output of Catch2 diagnostic messages. + FAIL_CHECK("uncaught exception in subprocess: " << ex.what()); + std::_Exit(EXIT_FAILURE); + } catch (...) { + // Allow default termination handler to translate the unknown exception type. + // This should also trigger the output of Catch2 diagnostic messages. + std::terminate(); + } + } + + // Parent: wait for child and handle returned status values. + else { + int status; + + int const ret = ::waitpid(pid, &status, 0); + + if (WIFEXITED(status) && WEXITSTATUS(status) != EXIT_SUCCESS) { + UNSCOPED_INFO("subprocess exited with a non-zero exit code: " << WEXITSTATUS(status)); + is_signal = false; + return WEXITSTATUS(status); + } + + // For unexpected signals, stop immediately. + else if (WIFSIGNALED(status)) { + int const signal = WTERMSIG(status); + char const* const sigstr = ::strsignal(signal); + UNSCOPED_INFO("subprocess was killed by signal: " << signal << " (" << (sigstr ? sigstr : "") << ")"); + is_signal = true; + return signal; + } + + // We don't expect any other failure condition. + else { + REQUIRE(ret != -1); + return 0; + } + } +} + +} // namespace test +} // namespace mongocxx + +#else + +namespace mongocxx { +namespace test { + +int subprocess(std::function fn, bool* is_signal_ptr) { + (void)fn; + (void)is_signal_ptr; + + SKIP("mongocxx::test::subprocess() is not supported"); + + return 0; // Unused. +} + +} // namespace test +} // namespace mongocxx + +#endif // !defined(_MSC_VER) + +TEST_CASE("counter", "[mongocxx][test][subprocess]") { + std::atomic_int counter{0}; + + CHECK_SUBPROCESS([&counter] { counter.fetch_add(1); }); + CHECK_SUBPROCESS([&counter] { counter.fetch_add(2); }); + CHECK_SUBPROCESS([&counter] { counter.fetch_add(3); }); + + // State of a subprocess must not be observable by the original process. + REQUIRE(counter.load() == 0); +} + +TEST_CASE("failure", "[mongocxx][test][subprocess]") { + auto is_signal = false; + CHECK_FALSE_SUBPROCESS([] { + // Try to silence noisy Catch2 output. + (void)::close(1); // stdout + (void)::close(2); // stderr + + FAIL("subprocess"); + }); + CHECK_FALSE(is_signal); +} + +TEST_CASE("skip", "[mongocxx][test][subprocess]") { + auto is_signal = false; + CHECK_SUBPROCESS( + [] { + // Try to silence noisy Catch2 output. + (void)::close(1); // stdout + (void)::close(2); // stderr + + SKIP("subprocess"); + }, + &is_signal); + CHECK_FALSE(is_signal); +} + +TEST_CASE("exception", "[mongocxx][test][subprocess]") { + auto is_signal = false; + CHECK_FALSE_SUBPROCESS( + [] { + // Try to silence noisy Catch2 output. + (void)::close(1); // stdout + (void)::close(2); // stderr + + throw std::runtime_error("subprocess"); + }, + &is_signal); + CHECK_FALSE(is_signal); +} + +TEST_CASE("unknown exception", "[mongocxx][test][subprocess]") { +#if !defined(_MSC_VER) + auto is_signal = false; + auto const ret = mongocxx::test::subprocess( + [] { + // Try to silence noisy Catch2 output. + (void)::close(1); // stdout + (void)::close(2); // stderr + + throw "subprocess"; + }, + &is_signal); + CHECK(is_signal); + CHECK(ret != 0); + CHECK(ret != SIGTERM); // std::terminate() + +#else + + CHECK_SUBPROCESS([] {}); + +#endif // !defined(_MSC_VER) +} diff --git a/src/mongocxx/test/subprocess.hh b/src/mongocxx/test/subprocess.hh new file mode 100644 index 0000000000..9c75bf3f41 --- /dev/null +++ b/src/mongocxx/test/subprocess.hh @@ -0,0 +1,60 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#include + +namespace mongocxx { +namespace test { + +// Execute `fn` in a forked subprocess. +// +// Should be invoked directly from the body of a TEST_CASE(), not within a SECTION(). Keep it simple! +// +// @param fn The function to be invoked within a subprocess. +// @param is_signal_ptr When not null, `*is_signal_ptr` is set to `true` if the return value is a signal rather than an +// exit code. +// +// @returns The exit code of the subprocess (`*is_signal_ptr` is `false`) or the signal used to kill the subprocess +// (`*is_signal_ptr` is `true`) . +int subprocess(std::function fn, bool* is_signal_ptr = nullptr); + +#if !defined(_MSC_VER) + +#define CHECK_SUBPROCESS(...) \ + if (1) { \ + int const ret = mongocxx::test::subprocess(__VA_ARGS__); \ + CHECK(ret == 0); \ + } else \ + ((void)0) + +#define CHECK_FALSE_SUBPROCESS(...) \ + if (1) { \ + int const ret = mongocxx::test::subprocess(__VA_ARGS__); \ + CHECK(ret != 0); \ + } else \ + ((void)0) + +#else + +#define CHECK_SUBPROCESS(...) SKIP("mongocxx::test::subprocess() is not supported") +#define CHECK_FALSE_SUBPROCESS(...) SKIP("mongocxx::test::subprocess() is not supported") + +#endif // !defined(_MSC_VER) + +} // namespace test +} // namespace mongocxx diff --git a/src/mongocxx/test/v1/exception.cpp b/src/mongocxx/test/v1/exception.cpp new file mode 100644 index 0000000000..875cc8926a --- /dev/null +++ b/src/mongocxx/test/v1/exception.cpp @@ -0,0 +1,62 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +// + +#include + +#include +#include + +namespace mongocxx { +namespace v1 { + +TEST_CASE("source", "[mongocxx][v1][error]") { + auto const& c = source_error_category(); + + SECTION("name") { + CHECK_THAT(c.name(), Catch::Matchers::Equals("mongocxx::v1::source_errc")); + } + + SECTION("message") { + CHECK(c.message(-1) == "mongocxx::v1::source_errc:-1"); + CHECK(c.message(0) == "zero"); + CHECK(c.message(1) == "mongocxx"); + CHECK(c.message(2) == "mongoc"); + CHECK(c.message(3) == "mongocrypt"); + CHECK(c.message(4) == "server"); + CHECK(c.message(5) == "mongocxx::v1::source_errc:5"); + } +} + +TEST_CASE("type", "[mongocxx][v1][error]") { + auto const& c = type_error_category(); + + SECTION("name") { + CHECK_THAT(c.name(), Catch::Matchers::Equals("mongocxx::v1::type_errc")); + } + + SECTION("message") { + CHECK(c.message(-1) == "mongocxx::v1::type_errc:-1"); + CHECK(c.message(0) == "zero"); + CHECK(c.message(1) == "invalid argument"); + CHECK(c.message(2) == "runtime error"); + CHECK(c.message(3) == "mongocxx::v1::type_errc:3"); + } +} + +} // namespace v1 +} // namespace mongocxx diff --git a/src/mongocxx/test/v1/exception.hh b/src/mongocxx/test/v1/exception.hh new file mode 100644 index 0000000000..402a9bf2bf --- /dev/null +++ b/src/mongocxx/test/v1/exception.hh @@ -0,0 +1,34 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +// + +#include + +CATCH_REGISTER_ENUM( + mongocxx::v1::source_errc, + mongocxx::v1::source_errc::zero, + mongocxx::v1::source_errc::mongocxx, + mongocxx::v1::source_errc::mongoc, + mongocxx::v1::source_errc::mongocrypt) + +CATCH_REGISTER_ENUM( + mongocxx::v1::type_errc, + mongocxx::v1::type_errc::zero, + mongocxx::v1::type_errc::invalid_argument, + mongocxx::v1::type_errc::runtime_error) diff --git a/src/mongocxx/test/v1/instance.cpp b/src/mongocxx/test/v1/instance.cpp new file mode 100644 index 0000000000..7c80662b2c --- /dev/null +++ b/src/mongocxx/test/v1/instance.cpp @@ -0,0 +1,206 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +// + +#include + +#include + +#include +#include + +#include + +#include + +#include + +#include + +#include +#include + +#if !defined(_MSC_VER) +#include +#endif + +namespace mongocxx { +namespace v1 { + +namespace { + +class custom_logger : public logger { + private: + using fn_type = std::function; + + fn_type _fn; + + public: + /* explicit(false) */ custom_logger(fn_type fn) : _fn{std::move(fn)} {} + + void operator()( + log_level level, + bsoncxx::v1::stdx::string_view domain, + bsoncxx::v1::stdx::string_view message) noexcept override { + _fn(level, domain, message); + } +}; + +} // namespace + +TEST_CASE("logger", "[mongocxx][v1][instance]") { +#if !defined(_MSC_VER) + class capture_stderr { + private: + int _pipes[2]; + int _stderr; // stderr + + public: + ~capture_stderr() { + ::dup2(_stderr, STDERR_FILENO); // Restore original stderr. + } + + capture_stderr(capture_stderr&&) = delete; + capture_stderr& operator=(capture_stderr&&) = delete; + capture_stderr(capture_stderr const&) = delete; + capture_stderr& operator=(capture_stderr const&) = delete; + + capture_stderr() + : _stderr{::dup(STDERR_FILENO)} // Save original stderr. + { + ::fflush(stderr); + REQUIRE(::pipe(_pipes) == 0); // Open redirection pipes. + REQUIRE(::dup2(_pipes[1], STDERR_FILENO) != -1); // Copy stderr to input pipe. + REQUIRE(::close(_pipes[1]) != -1); // Close original stderr. + + REQUIRE( + ::fcntl(_pipes[0], F_SETFL, ::fcntl(_pipes[0], F_GETFL) | O_NONBLOCK) != -1); // Do not block on read. + } + + std::string read() { + std::string res; + + { + // Capture everything up to this point. + // Avoid recursive macro expansion of `stderr` due to Catch expression decomposition. + auto const res = ::fflush(stderr); + REQUIRE(res == 0); + } + + while (true) { + char buf[BUFSIZ]; + auto const n = ::read(_pipes[0], buf, std::size_t{BUFSIZ - 1}); + + CHECKED_IF(n < 0) { + REQUIRE(errno == EAGAIN); // No data left in stream. + break; + } + else { + res.append(buf, static_cast(n)); + } + } + + return res; + } + }; + +#else + + class capture_stderr { + public: + std::string read() { + return {}; + } + }; + +#endif // !defined(_MSC_VER) + + { + auto const test_default = [] { + instance i; + + auto const output = [&] { + capture_stderr guard; + mongoc_log(MONGOC_LOG_LEVEL_WARNING, "mongocxx::v1::instance", "mongoc_log_default_handler"); + return guard.read(); + }(); + + CHECK_THAT( + output, + Catch::Matchers::ContainsSubstring("mongocxx::v1::instance") && + Catch::Matchers::ContainsSubstring("mongoc_log_default_handler")); + }; + CHECK_SUBPROCESS(test_default); + } + + { + auto const test_noop = [] { + instance i{nullptr}; + + auto const output = [&] { + capture_stderr guard; + mongoc_log(MONGOC_LOG_LEVEL_WARNING, "mongocxx::v1::instance", "SHOULD NOT BE LOGGED"); + return guard.read(); + }(); + + CHECK_THAT( + output, + !Catch::Matchers::ContainsSubstring("mongocxx::v1::instance") && + !Catch::Matchers::ContainsSubstring("SHOULD NOT BE LOGGED")); + }; + CHECK_SUBPROCESS(test_noop); + } + + { + auto const test_custom = [] { + int count = 0; + log_level level; + std::string domain; + std::string message; + + auto const fn = + [&](log_level _level, bsoncxx::v1::stdx::string_view _domain, bsoncxx::v1::stdx::string_view _message) { + ++count; + level = _level; + domain = std::string{_domain}; + message = std::string{_message}; + }; + + instance i{bsoncxx::make_unique(fn)}; + + mongoc_log(MONGOC_LOG_LEVEL_WARNING, "mongocxx::v1::instance", "custom_logger"); + + CHECK(count == 1); + CHECK(level == log_level::k_warning); + CHECK(domain == "mongocxx::v1::instance"); + CHECK(message == "custom_logger"); + }; + CHECK_SUBPROCESS(test_custom); + } +} + +TEST_CASE("stringify", "[mongocxx][test][v1][instance]") { + auto const test = [] { + instance i; + + REQUIRE(bsoncxx::test::stringify(i) == "mongocxx::v1::instance"); + }; + CHECK_SUBPROCESS(test); +} + +} // namespace v1 +} // namespace mongocxx diff --git a/src/mongocxx/test/v1/instance.hh b/src/mongocxx/test/v1/instance.hh new file mode 100644 index 0000000000..2faac1a5f9 --- /dev/null +++ b/src/mongocxx/test/v1/instance.hh @@ -0,0 +1,32 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +// + +#include + +namespace Catch { + +template <> +struct StringMaker { + static std::string convert(mongocxx::v1::instance const&) { + return "mongocxx::v1::instance"; + } +}; + +} // namespace Catch diff --git a/src/mongocxx/test/v1/logger.cpp b/src/mongocxx/test/v1/logger.cpp new file mode 100644 index 0000000000..2adfb74cf5 --- /dev/null +++ b/src/mongocxx/test/v1/logger.cpp @@ -0,0 +1,53 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +// + +#include + +#include + +namespace mongocxx { +namespace v1 { + +namespace { + +struct custom_logger : logger { + void operator()( + log_level level, + bsoncxx::v1::stdx::string_view domain, + bsoncxx::v1::stdx::string_view message) noexcept override { + (void)level; + (void)domain; + (void)message; + } +}; + +} // namespace + +// mongocxx::v1::logger must not unnecessarily impose special requirements on derived classes. +static_assert(std::is_nothrow_destructible::value, ""); +static_assert(std::is_nothrow_move_constructible::value, ""); +static_assert(std::is_copy_constructible::value, ""); +static_assert(std::is_default_constructible::value, ""); + +TEST_CASE("stringify", "[mongocxx][test][v1][logger]") { + // No point specializing StringMaker for abstract class mongocxx::v1::logger. + CHECK(bsoncxx::test::stringify(custom_logger{}) == "{?}"); +} + +} // namespace v1 +} // namespace mongocxx diff --git a/src/mongocxx/test/v1/logger.hh b/src/mongocxx/test/v1/logger.hh new file mode 100644 index 0000000000..3c8249d60e --- /dev/null +++ b/src/mongocxx/test/v1/logger.hh @@ -0,0 +1,37 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +// + +#include + +CATCH_REGISTER_ENUM( + mongocxx::v1::log_level, + mongocxx::v1::log_level::k_error, + mongocxx::v1::log_level::k_critical, + mongocxx::v1::log_level::k_warning, + mongocxx::v1::log_level::k_message, + mongocxx::v1::log_level::k_info, + mongocxx::v1::log_level::k_debug, + mongocxx::v1::log_level::k_trace) + +namespace Catch { + +// No point specializing StringMaker for abstract class mongocxx::v1::logger. + +} // namespace Catch diff --git a/src/mongocxx/test/v_noabi/instance.cpp b/src/mongocxx/test/v_noabi/instance.cpp index 1e5d5b9212..77fe2212ff 100644 --- a/src/mongocxx/test/v_noabi/instance.cpp +++ b/src/mongocxx/test/v_noabi/instance.cpp @@ -12,34 +12,50 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include +// + +#include +#include + +#include + +#include namespace { -TEST_CASE("instance", "[mongocxx][v_noabi][instance]") { - using namespace mongocxx; +using mongocxx::v_noabi::instance; + +using code = mongocxx::v_noabi::error_code; + +TEST_CASE("basic", "[mongocxx][v_noabi][instance]") { + auto const ret = mongocxx::test::subprocess([] { + using mongocxx::v_noabi::logic_error; - instance* inst = nullptr; + instance* inst = nullptr; - // instance::current creates instance when one has not already been created - REQUIRE_NOTHROW(inst = &instance::current()); + // instance::current creates instance when one has not already been created + REQUIRE_NOTHROW(inst = &instance::current()); - // multiple instances cannot be created" - REQUIRE_THROWS_AS(instance{}, logic_error); + // multiple instances cannot be created" + REQUIRE_THROWS_WITH_CODE(instance{}, code::k_cannot_recreate_instance); + REQUIRE_THROWS_AS(instance{}, logic_error); - // instance::current works when instance is alive - REQUIRE_NOTHROW(instance::current()); + // instance::current works when instance is alive + REQUIRE_NOTHROW(instance::current()); - // an instance cannot be created after one has been destroyed - inst->~instance(); - inst = nullptr; - REQUIRE_THROWS_AS(instance{}, logic_error); + // an instance cannot be created after one has been destroyed + inst->~instance(); + inst = nullptr; + REQUIRE_THROWS_WITH_CODE(instance{}, code::k_cannot_recreate_instance); + REQUIRE_THROWS_AS(instance{}, logic_error); - // instance::current throws if an instance has already been destroyed - REQUIRE_THROWS_AS(instance::current(), logic_error); + // instance::current throws if an instance has already been destroyed + REQUIRE_THROWS_WITH_CODE(instance::current(), code::k_instance_destroyed); + REQUIRE_THROWS_AS(instance::current(), logic_error); + }); + REQUIRE(ret == 0); } } // namespace diff --git a/src/mongocxx/test/v_noabi/logging.cpp b/src/mongocxx/test/v_noabi/logging.cpp index 4d9fb86a67..fb2938f7ec 100644 --- a/src/mongocxx/test/v_noabi/logging.cpp +++ b/src/mongocxx/test/v_noabi/logging.cpp @@ -12,10 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +// + #include #include -#include #include @@ -23,6 +26,8 @@ #include +#include + namespace { using namespace mongocxx; @@ -49,18 +54,21 @@ class reset_log_handler_when_done { } }; -TEST_CASE("a user-provided log handler will be used for logging output", "[instance]") { - reset_log_handler_when_done rlhwd; +TEST_CASE("custom", "[mongocxx][v_noabi][logger]") { + auto const ret = mongocxx::test::subprocess([] { + reset_log_handler_when_done rlhwd; - std::vector events; - mongocxx::instance driver{bsoncxx::make_unique(&events)}; + std::vector events; + mongocxx::instance driver{bsoncxx::make_unique(&events)}; - // The libmongoc namespace mocking system doesn't play well with varargs - // functions, so we use a bare mongoc_log call here. - mongoc_log(::MONGOC_LOG_LEVEL_ERROR, "foo", "bar"); + // The libmongoc namespace mocking system doesn't play well with varargs + // functions, so we use a bare mongoc_log call here. + mongoc_log(::MONGOC_LOG_LEVEL_ERROR, "foo", "bar"); - REQUIRE(events.size() == 1); - REQUIRE(events[0] == std::make_tuple(log_level::k_error, "foo", "bar")); + REQUIRE(events.size() == 1); + REQUIRE(events[0] == std::make_tuple(log_level::k_error, "foo", "bar")); + }); + REQUIRE(ret == 0); } } // namespace From dc60649de44086cbb141dbb35c08834ae9bb4392 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 9 Oct 2025 11:22:45 -0500 Subject: [PATCH 02/33] CXX-3236 add mongocxx v1 declarations --- .../include/mongocxx/v1/aggregate_options.hpp | 189 ++- src/mongocxx/include/mongocxx/v1/apm.hpp | 270 ++++- .../include/mongocxx/v1/auto_encryption.hpp | 197 +++- .../include/mongocxx/v1/bulk_write.hpp | 1030 ++++++++++++++++- .../include/mongocxx/v1/change_stream.hpp | 384 +++++- src/mongocxx/include/mongocxx/v1/client.hpp | 322 +++++- .../include/mongocxx/v1/client_encryption.hpp | 350 +++++- .../include/mongocxx/v1/client_session.hpp | 349 +++++- .../include/mongocxx/v1/collection.hpp | 893 +++++++++++++- .../include/mongocxx/v1/count_options.hpp | 143 ++- src/mongocxx/include/mongocxx/v1/cursor.hpp | 233 +++- src/mongocxx/include/mongocxx/v1/data_key.hpp | 100 +- src/mongocxx/include/mongocxx/v1/database.hpp | 313 ++++- .../mongocxx/v1/delete_many_options.hpp | 119 +- .../mongocxx/v1/delete_many_result.hpp | 69 +- .../mongocxx/v1/delete_one_options.hpp | 119 +- .../include/mongocxx/v1/delete_one_result.hpp | 67 +- .../include/mongocxx/v1/detail/macros.hpp | 2 +- .../include/mongocxx/v1/distinct_options.hpp | 108 +- src/mongocxx/include/mongocxx/v1/encrypt.hpp | 155 +++ .../v1/estimated_document_count_options.hpp | 97 +- .../mongocxx/v1/events/command_failed.hpp | 60 +- .../mongocxx/v1/events/command_started.hpp | 60 +- .../mongocxx/v1/events/command_succeeded.hpp | 59 +- .../mongocxx/v1/events/server_closed.hpp | 33 +- .../mongocxx/v1/events/server_description.hpp | 95 +- .../v1/events/server_description_changed.hpp | 45 +- .../v1/events/server_heartbeat_failed.hpp | 41 +- .../v1/events/server_heartbeat_started.hpp | 31 +- .../v1/events/server_heartbeat_succeeded.hpp | 43 +- .../mongocxx/v1/events/server_opening.hpp | 34 +- .../mongocxx/v1/events/topology_closed.hpp | 22 +- .../v1/events/topology_description.hpp | 46 +- .../events/topology_description_changed.hpp | 32 +- .../mongocxx/v1/events/topology_opening.hpp | 22 +- .../v1/find_one_and_delete_options.hpp | 153 ++- .../v1/find_one_and_replace_options.hpp | 188 ++- .../v1/find_one_and_update_options.hpp | 200 +++- .../include/mongocxx/v1/find_options.hpp | 287 ++++- .../include/mongocxx/v1/gridfs/bucket.hpp | 404 ++++++- .../include/mongocxx/v1/gridfs/downloader.hpp | 138 ++- .../mongocxx/v1/gridfs/upload_options.hpp | 82 +- .../mongocxx/v1/gridfs/upload_result.hpp | 66 +- .../include/mongocxx/v1/gridfs/uploader.hpp | 174 ++- src/mongocxx/include/mongocxx/v1/hint.hpp | 155 ++- src/mongocxx/include/mongocxx/v1/indexes.hpp | 648 +++++++++++ .../mongocxx/v1/insert_many_options.hpp | 105 +- .../mongocxx/v1/insert_many_result.hpp | 80 +- .../mongocxx/v1/insert_one_options.hpp | 94 +- .../include/mongocxx/v1/insert_one_result.hpp | 69 +- src/mongocxx/include/mongocxx/v1/pipeline.hpp | 224 +++- src/mongocxx/include/mongocxx/v1/pool.hpp | 259 ++++- src/mongocxx/include/mongocxx/v1/range.hpp | 123 +- .../include/mongocxx/v1/read_concern.hpp | 183 ++- .../include/mongocxx/v1/read_preference.hpp | 159 ++- .../mongocxx/v1/replace_one_options.hpp | 152 ++- .../mongocxx/v1/replace_one_result.hpp | 84 +- .../include/mongocxx/v1/return_document.hpp | 18 +- .../v1/rewrap_many_datakey_options.hpp | 83 +- .../v1/rewrap_many_datakey_result.hpp | 55 +- .../include/mongocxx/v1/search_indexes.hpp | 351 +++++- .../include/mongocxx/v1/server_api.hpp | 147 +++ .../include/mongocxx/v1/server_error-fwd.hpp | 2 +- .../include/mongocxx/v1/server_error.hpp | 93 +- src/mongocxx/include/mongocxx/v1/tls.hpp | 125 +- .../include/mongocxx/v1/transaction.hpp | 105 +- .../mongocxx/v1/update_many_options.hpp | 165 ++- .../mongocxx/v1/update_many_result.hpp | 95 +- .../mongocxx/v1/update_one_options.hpp | 165 ++- .../include/mongocxx/v1/update_one_result.hpp | 89 +- src/mongocxx/include/mongocxx/v1/uri.hpp | 373 +++++- .../include/mongocxx/v1/write_concern.hpp | 237 +++- src/mongocxx/lib/mongocxx/v1/server_error.cpp | 15 + 73 files changed, 12137 insertions(+), 140 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp b/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp index 8e3b5f5cf3..bb9cb08c67 100644 --- a/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp @@ -20,18 +20,205 @@ #include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for an "aggregate" command. /// +/// Supported fields include: +/// - `allow_disk_use` ("allowDiskUse") +/// - `batch_size` ("batchSize") +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `collation` +/// - `comment` +/// - `hint` +/// - `let` +/// - `max_time` ("maxTimeMS") +/// - `read_concern` ("readConcern") +/// - `read_preference` ("readPreference") +/// - `write_concern` ("writeConcern") +/// /// @see /// - [`aggregate` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/aggregation/) /// /// @attention This feature is experimental! It is not ready for use! /// -class aggregate_options {}; +class aggregate_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~aggregate_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() aggregate_options(aggregate_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) operator=(aggregate_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() aggregate_options(aggregate_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) operator=(aggregate_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() aggregate_options(); + + /// + /// Set the "allowDiskUse" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) allow_disk_use(bool allow_disk_use); + + /// + /// Return the current "allowDiskUse" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) allow_disk_use() const; + + /// + /// Set the "batchSize" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) batch_size(std::int32_t batch_size); + + /// + /// Return the current "batchSize" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) batch_size() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) let() const; + + /// + /// Set the "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) read_preference(v1::read_preference rp); + + /// + /// Return the current "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_preference() const; + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) write_concern(v1::write_concern write_concern); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "readConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) read_concern(v1::read_concern read_concern); + + /// + /// Return the current "readConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_concern() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(aggregate_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/apm.hpp b/src/mongocxx/include/mongocxx/v1/apm.hpp index f8cb6da874..fb27526226 100644 --- a/src/mongocxx/include/mongocxx/v1/apm.hpp +++ b/src/mongocxx/include/mongocxx/v1/apm.hpp @@ -20,6 +20,26 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +51,255 @@ namespace v1 { /// - [Command Logging and Monitoring (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/command-logging-and-monitoring/command-logging-and-monitoring/) /// - [SDAM Logging and Monitoring Specification (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring/) /// -class apm {}; +class apm { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~apm(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() apm(apm&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) operator=(apm&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() apm(apm const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) operator=(apm const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All event handlers are initialized as "empty". + /// + MONGOCXX_ABI_EXPORT_CDECL() apm(); + + /// + /// Set the "CommandStartedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_command_started( + std::function fn); + + /// + /// Return the current "CommandStartedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + command_started() const; + + /// + /// Set the "CommandFailedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_command_failed( + std::function fn); + + /// + /// Return the current the "CommandFailedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + command_failed() const; + + /// + /// Set the "CommandSucceededEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_command_succeeded( + std::function fn); + + /// + /// Return the current the "CommandSucceededEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + command_succeeded() const; + + /// + /// Set the "ServerOpeningEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_server_opening( + std::function fn); + + /// + /// Return the current the "ServerOpeningEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + server_opening() const; + + /// + /// Set the "ServerClosedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_server_closed( + std::function fn); + + /// + /// Return the current the "ServerClosedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + server_closed() const; + + /// + /// Set the "ServerDescriptionChangedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_server_description_changed( + std::function fn); + + /// + /// Return the current the "ServerDescriptionChangedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + server_description_changed() const; + + /// + /// Set the "TopologyOpeningEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_topology_opening( + std::function fn); + + /// + /// Return the current the "TopologyOpeningEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + topology_opening() const; + + /// + /// Set the "TopologyClosedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_topology_closed( + std::function fn); + + /// + /// Return the current the "TopologyClosedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + topology_closed() const; + + /// + /// Set the "TopologyDescriptionChangedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_topology_description_changed( + std::function fn); + + /// + /// Return the current the "TopologyDescriptionChangedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + topology_description_changed() const; + + /// + /// Set the "ServerHeartbeatStartedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_heartbeat_started( + std::function fn); + + /// + /// Return the current the "ServerHeartbeatStartedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + heartbeat_started() const; + + /// + /// Set the "ServerHeartbeatFailedEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_heartbeat_failed( + std::function fn); + + /// + /// Return the current the "ServerHeartbeatFailedEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + heartbeat_failed() const; + + /// + /// Set the "ServerHeartbeatSucceededEvent" handler. + /// + /// @warning It is undefined behavior for the handler to throw an exception. + /// + /// @par Preconditions: + /// - `fn` MUST NOT throw an exception when invoked. + /// + MONGOCXX_ABI_EXPORT_CDECL(apm&) on_heartbeat_succeeded( + std::function fn); + + /// + /// Return the current the "ServerHeartbeatSucceededEvent" handler. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::function) + heartbeat_succeeded() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp b/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp index a1c41a55b6..7f5b2055f9 100644 --- a/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp +++ b/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp @@ -20,17 +20,212 @@ #include +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related In-Use Encryption configuration. /// +/// Supported fields include: +/// - `bypass_auto_encryption` ("bypassAutoEncryption") +/// - `bypass_query_analysis` ("bypassQueryAnalysis") +/// - `encrypted_fields_map` ("encryptedFieldsMap") +/// - `extra_options` ("extraOptions") +/// - `key_vault_client` ("keyVaultClient") +/// - `key_vault_namespace` ("keyVaultNamespace") +/// - `key_vault_pool` ("keyVaultPool") +/// - `kms_providers` ("kmsProviders") +/// - `schema_map` ("schemaMap") +/// - `tls_options` ("tlsOptions") +/// /// @see /// - [MongoClient Options for Queryable Encryption (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/qe-options-clients/) /// - [MongoClient Options for CSFLE](https://www.mongodb.com/docs/manual/core/csfle/reference/csfle-options-clients/) /// -class auto_encryption {}; +class auto_encryption { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~auto_encryption(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() auto_encryption(auto_encryption&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) operator=(auto_encryption&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() auto_encryption(auto_encryption const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) operator=(auto_encryption const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() auto_encryption(); + + /// + /// Set the "keyVaultClient" field. + /// + /// @important The associated client MUST outlive any client or pool configured to use this option. + /// + /// @note The "keyVaultClient" and "keyVaultPool" fields are mutually exclusive. + /// + /// @param v Equivalent to "unset" when null. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) key_vault_client(v1::client* v); + + /// + /// Return the current "keyVaultClient" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::client*) key_vault_client() const; + + /// + /// Set the "keyVaultPool" field. + /// + /// Equivalent to "keyVaultClient", but acquires a client from the given pool on-demand. + /// + /// @important The associated pool MUST outlive any client or pool configured to use this option. + /// + /// @note The "keyVaultClient" and "keyVaultPool" fields are mutually exclusive. + /// + /// @param v Equivalent to "unset" when null. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) key_vault_pool(v1::pool* v); + + /// + /// Return the current "keyVaultPool" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::pool*) key_vault_pool() const; + + /// + /// The name of a database and a collection. + /// + /// ```cpp + /// ns_pair{"db", "coll"} // db.coll + /// ``` + /// + using ns_pair = std::pair; + + /// + /// Set the "keyVaultNamespace" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) key_vault_namespace(ns_pair v); + + /// + /// Return the current "keyVaultNamespace" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) key_vault_namespace() const; + + /// + /// Set the "kmsProviders" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) kms_providers(bsoncxx::v1::document::value v); + + /// + /// Return the current "kmsProviders" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) kms_providers() const; + + /// + /// Set the "tlsOptions" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) tls_opts(bsoncxx::v1::document::value v); + + /// + /// Return the current "tlsOptions" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_opts() const; + + /// + /// Set the "schemaMap" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) schema_map(bsoncxx::v1::document::value v); + + /// + /// Return the "schemaMap" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) schema_map() const; + + /// + /// Set the "encryptedFieldsMap" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) encrypted_fields_map(bsoncxx::v1::document::value v); + + /// + /// Return the current "encryptedFieldsMap" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) encrypted_fields_map() const; + + /// + /// Set the "bypassAutoEncryption" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) bypass_auto_encryption(bool v); + + /// + /// Return the current "bypassAutoEncryption" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) bypass_auto_encryption() const; + + /// + /// Set the "bypassQueryAnalysis" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) bypass_query_analysis(bool v); + + /// + /// Return the current "bypassQueryAnalysis" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) bypass_query_analysis() const; + + /// + /// Set the "extraOptions" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption&) extra_options(bsoncxx::v1::document::value v); + + /// + /// Return the current "extraOptions" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) extra_options() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp index c08e249fec..96a4620b3c 100644 --- a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp +++ b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp @@ -16,6 +16,29 @@ #include +// + +#include + +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -33,105 +56,1014 @@ class bulk_write { /// /// Enumeration identifying the type of a write operation. /// - enum class type {}; + enum class type { + /// + /// An "Insert One" operation. + /// + k_insert_one, + + /// + /// A "Delete One" operation. + /// + k_delete_one, + + /// + /// A "Delete Many" operation. + /// + k_delete_many, + + /// + /// An "Update One" operation. + /// + k_update_one, + + /// + /// An "Update Many" operation. + /// + k_update_many, + + /// + /// A "Replace One" operation. + /// + k_replace_one, + }; + + class insert_one; + class update_one; + class update_many; + class replace_one; + class delete_one; + class delete_many; + class single; + class options; + class result; + + /// + /// Return true when there are no appended operations. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) empty() const; + + /// + /// Append a single write operation. + /// + /// @throws mongocxx::v1::exception when a client-side error is encountered. + /// + MONGOCXX_ABI_EXPORT_CDECL(bulk_write&) append(single op); + + /// + /// Execute the appended operations. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) execute(); +}; + +/// +/// A single "Insert One" write operation. +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::insert_one { + public: + /// + /// The document to be inserted. + /// + bsoncxx::v1::document::value value; + + /// + /// Initialize with `doc`. + /// + /* explicit(false) */ insert_one(bsoncxx::v1::document::value doc) : value{std::move(doc)} {} + + /// + /// Equivalent to `this->value`. + /// + bsoncxx::v1::document::value const& document() const { + return value; + } +}; + +/// +/// A single "Update One" write operation. +/// +/// Supported fields include: +/// - `array_filters` ("arrayFilters") +/// - `collation` +/// - `filter` +/// - `hint` +/// - `sort` +/// - `update` +/// - `upsert` +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::update_one { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~update_one(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one(update_one&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one&) operator=(update_one&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one(update_one const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one&) operator=(update_one const& other); + + /// + /// Initialize with the given "filter" and "update" documents. + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one(bsoncxx::v1::document::value filter, bsoncxx::v1::document::value update); + + /// + /// Initialize with the given "filter" document and "update" aggregation pipeline. + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one(bsoncxx::v1::document::value filter, v1::pipeline update); + + /// + /// Return the current "filter" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const; + + /// + /// Return the current "update" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) update() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one&) collation(bsoncxx::v1::document::value v); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one&) hint(v1::hint v); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one&) sort(bsoncxx::v1::document::value v); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one&) upsert(bool v); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; + + /// + /// Set the "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one&) array_filters(bsoncxx::v1::array::value v); + + /// + /// Return the current "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) array_filters() const; +}; + +/// +/// A single "Update Many" write operation. +/// +/// Supported fields include: +/// - `array_filters` ("arrayFilters") +/// - `collation` +/// - `hint` +/// - `upsert` +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::update_many { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~update_many(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many(update_many&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many&) operator=(update_many&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many(update_many const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many&) operator=(update_many const& other); + + /// + /// Initialize with the given "filter" and "update" documents. + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many(bsoncxx::v1::document::value filter, bsoncxx::v1::document::value update); + + /// + /// Initialize with the given "filter" document and "update" aggregation pipeline. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many(bsoncxx::v1::document::value filter, pipeline const& update); + + /// + /// Return the current "filter" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const; + + /// + /// Return the current "update" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) update() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many&) collation(bsoncxx::v1::document::value v); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many&) hint(v1::hint v); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many&) upsert(bool v); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; + + /// + /// Set the "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many&) array_filters(bsoncxx::v1::array::value v); + + /// + /// Return the current "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) array_filters() const; +}; + +/// +/// A single "Replace One" write operation. +/// +/// Supported fields include: +/// - `collation` +/// - `filter` +/// - `hint` +/// - `replacement` +/// - `sort` +/// - `upsert` +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::replace_one { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~replace_one(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one(replace_one&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one&) operator=(replace_one&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one(replace_one const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one&) operator=(replace_one const& other); + + /// + /// Initialize with the given "filter" and "replacement" documents. + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one( + bsoncxx::v1::document::value filter, + bsoncxx::v1::document::value replacement); + + /// + /// Return the current "filter" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const; + + /// + /// Return the current "replacement" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) replacement() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one&) collation(bsoncxx::v1::document::value v); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one&) hint(v1::hint v); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one&) sort(bsoncxx::v1::document::value v); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one&) upsert(bool v); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; +}; + +/// +/// A single "Delete One" write operation. +/// +/// Supported fields include: +/// - `collation` +/// - `filter` +/// - `hint` +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::delete_one { + private: + class impl; + std::unique_ptr _impl; + public: /// - /// A single "Insert One" write operation. + /// Destroy this object. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// @warning Invalidates all associated views. /// - /// @attention This feature is experimental! It is not ready for use! + MONGOCXX_ABI_EXPORT_CDECL() ~delete_one(); + + /// + /// Move constructor. /// - class insert_one {}; + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one(delete_one&& other) noexcept; /// - /// A single "Update One" write operation. + /// Move assignment. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. /// - /// @attention This feature is experimental! It is not ready for use! + MONGOCXX_ABI_EXPORT_CDECL(delete_one&) operator=(delete_one&& other) noexcept; + /// - class update_one {}; + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one(delete_one const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one&) operator=(delete_one const& other); + + /// + /// Initialize with the given "filter". + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() delete_one(bsoncxx::v1::document::value filter); /// - /// A single "Update Many" write operation. + /// Return the current "filter" field. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one&) collation(bsoncxx::v1::document::value v); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + /// - /// @attention This feature is experimental! It is not ready for use! + /// Set the "hint" field. /// - class update_many {}; + MONGOCXX_ABI_EXPORT_CDECL(delete_one&) hint(v1::hint v); /// - /// A single "Replace One" write operation. + /// Return the current "hint" field. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; +}; + +/// +/// A single "Delete Many" write operation. +/// +/// Supported fields include: +/// - `collation` +/// - `filter` +/// - `hint` +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::delete_many { + private: + class impl; + std::unique_ptr _impl; + + public: /// - /// @attention This feature is experimental! It is not ready for use! + /// Destroy this object. /// - class replace_one {}; + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~delete_many(); /// - /// A single "Delete One" write operation. + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many(delete_many&& other) noexcept; + /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// Move assignment. /// - /// @attention This feature is experimental! It is not ready for use! + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. /// - class delete_one {}; + MONGOCXX_ABI_EXPORT_CDECL(delete_many&) operator=(delete_many&& other) noexcept; /// - /// A single "Delete Many" write operation. + /// Copy construction. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + MONGOCXX_ABI_EXPORT_CDECL() delete_many(delete_many const& other); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Copy assignment. /// - class delete_many {}; + MONGOCXX_ABI_EXPORT_CDECL(delete_many&) operator=(delete_many const& other); /// - /// A single write operation. + /// Initialize with the given "filter". + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) - /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) + explicit MONGOCXX_ABI_EXPORT_CDECL() delete_many(bsoncxx::v1::document::value filter); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "filter" field. /// - class single {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const; /// - /// Options for a write operation. + /// Set the "collation" field. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) - /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) + MONGOCXX_ABI_EXPORT_CDECL(delete_many&) collation(bsoncxx::v1::document::value v); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "collation" field. /// - class options {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; /// - /// The result of a write operation. + /// Set the "hint" field. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) - /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) + MONGOCXX_ABI_EXPORT_CDECL(delete_many&) hint(v1::hint v); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; +}; + +/// +/// A single write operation. +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::single { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated references. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~single(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() single(single&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(single&) operator=(single&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() single(single const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(single&) operator=(single const& other); + + /// + /// Initialize with `op`. + /// + /// @{ + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(insert_one op); + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(update_one op); + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(update_many op); + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(delete_one op); + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(delete_many op); + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() single(replace_one op); + /// @} + /// + + /// + /// Return the type of this write operation. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::type) type() const; + + /// + /// Return this write operation as an @ref mongocxx::v1::bulk_write::insert_one. + /// + /// @par Preconditions: + /// - `this->type() == mongocxx::v1::bulk_write::type::k_insert_one` + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(insert_one const&) get_insert_one() const&; + MONGOCXX_ABI_EXPORT_CDECL(insert_one&&) get_insert_one() &&; + /// @} + /// + + /// + /// Return this write operation as an @ref mongocxx::v1::bulk_write::update_one. + /// + /// @par Preconditions: + /// - `this->type() == mongocxx::v1::bulk_write::type::k_update_one` + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(update_one const&) get_update_one() const&; + MONGOCXX_ABI_EXPORT_CDECL(update_one&&) get_update_one() &&; + /// @} + /// + + /// + /// Return this write operation as an @ref mongocxx::v1::bulk_write::update_many. + /// + /// @par Preconditions: + /// - `this->type() == mongocxx::v1::bulk_write::type::k_update_many` + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(update_many const&) get_update_many() const&; + MONGOCXX_ABI_EXPORT_CDECL(update_many&&) get_update_many() &&; + /// @} + /// + + /// + /// Return this write operation as an @ref mongocxx::v1::bulk_write::delete_one. + /// + /// @par Preconditions: + /// - `this->type() == mongocxx::v1::bulk_write::type::k_delete_one` + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(delete_one const&) get_delete_one() const&; + MONGOCXX_ABI_EXPORT_CDECL(delete_one&&) get_delete_one() &&; + /// @} + /// + + /// + /// Return this write operation as an @ref mongocxx::v1::bulk_write::delete_many. + /// + /// @par Preconditions: + /// - `this->type() == mongocxx::v1::bulk_write::type::k_delete_many` + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(delete_many const&) get_delete_many() const&; + MONGOCXX_ABI_EXPORT_CDECL(delete_many&&) get_delete_many() &&; + /// @} + /// + + /// + /// Return this write operation as an @ref mongocxx::v1::bulk_write::replace_one. + /// + /// @par Preconditions: + /// - `this->type() == mongocxx::v1::bulk_write::type::k_replace_one` + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(replace_one const&) get_replace_one() const&; + MONGOCXX_ABI_EXPORT_CDECL(replace_one&&) get_replace_one() &&; + /// @} + /// +}; + +/// +/// Options for a bulk write operation. +/// +/// Supported fields include: +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `comment` +/// - `let` +/// - `ordered` +/// - `write_concern` ("writeConcern") +/// +/// @see +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) bypass_document_validation() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "ordered" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) ordered(bool ordered); + + /// + /// Return the current "ordered" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) ordered() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) write_concern(v1::write_concern wc); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; +}; + +/// +/// The result of a write operation. +/// +/// Supported fields include: +/// - `inserted_count` ("nInserted" or "insertedCount") +/// - `matched_count` ("nMatched" or "matchedCount") +/// - `modified_count` ("nModified" or "modifiedCount") +/// - `deleted_count` ("nDeleted" or "deletedCount") +/// - `upserted_count` ("nUpserted" or "upsertedCount") +/// - `upserted_ids` ("upserted" or "upsertedIds") +/// +/// @important The raw server response is translated by mongoc into the Bulk Write API specification format even when +/// the CRUD API specification is used to implement the requested operations (see: `MONGOC_WRITE_RESULT_COMPLETE`). +/// +/// @see +/// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) +/// - [Bulk Write API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/bulk-write/) +/// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) +/// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() result(result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(result&) operator=(result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() result(result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(result&) operator=(result const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() result(); + + /// + /// Return the value of the mongoc "nInserted" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) inserted_count() const; + + /// + /// Return the value of the mongoc "nMatched" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) matched_count() const; + + /// + /// Return the value of the mongoc "nModified" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) modified_count() const; + + /// + /// Return the value of the mongoc "nDeleted" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) deleted_count() const; + + /// + /// Return the value of the mongoc "nUpserted" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) upserted_count() const; + + /// + /// A map from the operation index to the upserted document ID. + /// + using id_map = std::map; + + /// + /// Return a map from the operation index to the upserted document ID. + /// + /// @returns Empty when the "upserted" field is not present or is empty. + /// + MONGOCXX_ABI_EXPORT_CDECL(id_map) upserted_ids() const; + + /// + /// Compare equal when `lhs.raw()` and `rhs.raw()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(result const& lhs, result const& rhs); + + friend bool operator!=(result const& lhs, result const& rhs) { + return !(lhs == rhs); + } + /// @} /// - class result {}; }; } // namespace v1 } // namespace mongocxx +#include + /// /// @file /// Provides entities related to write operations. diff --git a/src/mongocxx/include/mongocxx/v1/change_stream.hpp b/src/mongocxx/include/mongocxx/v1/change_stream.hpp index 87ae2c7b0d..327118ed9b 100644 --- a/src/mongocxx/include/mongocxx/v1/change_stream.hpp +++ b/src/mongocxx/include/mongocxx/v1/change_stream.hpp @@ -20,24 +20,402 @@ #include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// A MongoDB change stream. /// +/// @attention This feature is experimental! It is not ready for use! +/// /// @see /// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) /// class change_stream { + private: + class impl; + std::unique_ptr _impl; + + public: + class options; + + class iterator; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views and iterators. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~change_stream(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() change_stream(change_stream&& other) noexcept; + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(change_stream&) operator=(change_stream&& other) noexcept; + + /// + /// This class is not copyable. + /// + change_stream(change_stream const&) = delete; + + /// + /// This class is not copyable. /// - /// Options for @ref mongocxx::v1::change_stream. + change_stream& operator=(change_stream const&) = delete; + + /// + /// Return an iterator associated with this change stream. + /// + /// @important All iterators associated with the same change stream object share the same state. + /// + /// This function advances the underlying cursor to obtain the next (first) event document. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator) begin(); + + /// + /// Return an end iterator. + /// + /// @important The end iterator has no associated change stream. + /// + iterator end() const; + + /// + /// Return the resume token for this change stream. /// - /// @attention This feature is experimental! It is not ready for use! + /// @returns Empty document when not available. /// - class options {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) get_resume_token() const; }; +/// +/// Options for @ref mongocxx::v1::change_stream. +/// +/// Supported fields include: +/// - batch_size ("batchSize") +/// - collation +/// - comment +/// - full_document ("fullDocument") +/// - full_document_before_change ("fullDocumentBeforeChange") +/// - max_await_time ("maxAwaitTimeMS") +/// - resume_after ("resumeAfter") +/// - start_after ("startAfter") +/// - start_at_operation_time ("startAtOperationTime") +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class change_stream::options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Set the "batchSize" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) batch_size(std::int32_t v); + + /// + /// Return the current "batchSize" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) batch_size() const; + + /// + /// Set the "collation" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) collation(bsoncxx::v1::document::value v); + + /// + /// Return the current "collation" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "comment" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) comment(bsoncxx::v1::types::value v); + + /// + /// Return the current "comment" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; + + /// + /// Set the "fullDocument" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) full_document(std::string v); + + /// + /// Return the current "fullDocument" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) full_document() const; + + /// + /// Set the "fullDocumentBeforeChange" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) full_document_before_change(std::string v); + + /// + /// Return the current "fullDocumentBeforeChange" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) full_document_before_change() + const; + + /// + /// Set the "maxAwaitTimeMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) max_await_time(std::chrono::milliseconds v); + + /// + /// Return the current "maxAwaitTimeMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_await_time() const; + + /// + /// Set the "resumeAfter" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) resume_after(bsoncxx::v1::document::value v); + + /// + /// Return the current "resumeAfter" option. + /// + /// @returns Empty optional when the "resumeAfter" option is unset. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) resume_after() const; + + /// + /// Set the "startAfter" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) start_after(bsoncxx::v1::document::value v); + + /// + /// Return the current "startAfter" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) start_after() const; + + /// + /// Set the "startAtOperationTime" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) start_at_operation_time(bsoncxx::v1::types::b_timestamp v); + + /// + /// Return the current "startAtOperationTime" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) start_at_operation_time() + const; +}; + +/// +/// An iterator over change stream events. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +/// @important All iterators associated with the same change stream object share the same state. +/// @important The end iterator has no associated change stream. +/// +/// @note This iterator almost satisfies Cpp17ForwardIterator, but `std::iterator_traits::reference` is defined as +/// `value_type`, similar to `std::vector::iterator` and `std::istreambuf_iterator`. Therefore, this iterator +/// only fully satisfies Cpp17InputIterator. +/// +/// @see +/// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) +/// +class change_stream::iterator { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Provide `std::iterator_traits::iterator_category`. + /// + using iterator_category = std::input_iterator_tag; + + /// + /// Provide `std::iterator_traits::value_type`. + /// + using value_type = bsoncxx::v1::document::view; + + /// + /// Provide `std::iterator_traits::difference_type`. + /// + using difference_type = std::ptrdiff_t; + + /// + /// Provide `std::iterator_traits::pointer`. + /// + using pointer = value_type const*; + + /// + /// Provide `std::iterator_traits::reference`. + /// + using reference = value_type; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~iterator(); + + /// + /// Move construction. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() iterator(iterator&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator&) operator=(iterator&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() iterator(iterator const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator&) operator=(iterator const& other); + + /// + /// Initialize as an end iterator. + /// + MONGOCXX_ABI_EXPORT_CDECL() iterator(); + + /// + /// Return the current event document. + /// + /// @returns Empty when there is no event document available. + /// + MONGOCXX_ABI_EXPORT_CDECL(value_type) operator*() const; + + /// + /// Access the current event document. + /// + /// @par Preconditions: + /// - `*this` does not compare equal to the end iterator. + /// + MONGOCXX_ABI_EXPORT_CDECL(pointer) operator->() const; + + /// + /// Increment this iterator. + /// + /// Advance the underlying cursor to obtain the next event document. + /// Compare equal to the end iterator when there are no event documents available. + /// + /// @note Pre-increment and post-increment are equivalent. + /// + /// @warning Invalidates all views to the current event document. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator&) operator++(); + + /// @copydoc operator++() + iterator& operator++(int) { + return this->operator++(); + } + + /// + /// Equality comparison. + /// + /// `lhs` and `rhs` compare equal when: + /// - both are associated with the same change stream object, or + /// - both are end iterators, or + /// - one is an end iterator and the other has no event document available. + /// + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(iterator const& lhs, iterator const& rhs); + + /// + /// Equivalent to `!(lhs == rhs)`. + /// + friend bool operator!=(iterator const& lhs, iterator const& rhs) { + return !(lhs == rhs); + } +}; + +inline change_stream::iterator change_stream::end() const { + return {}; +} + } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/client.hpp b/src/mongocxx/include/mongocxx/v1/client.hpp index 964eca92fe..7e2d42bbac 100644 --- a/src/mongocxx/include/mongocxx/v1/client.hpp +++ b/src/mongocxx/include/mongocxx/v1/client.hpp @@ -20,6 +20,27 @@ #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -35,12 +56,307 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class client { + private: + class impl; + std::unique_ptr _impl; + + public: + class options; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views, databases, cursors, client sessions, and change streams. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~client(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() client(client&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(client&) operator=(client&& other) noexcept; + + /// + /// This class is not copyable. + /// + MONGOCXX_ABI_EXPORT_CDECL() client(client const& other); + + /// + /// This class is not copyable. + /// + MONGOCXX_ABI_EXPORT_CDECL(client&) operator=(client const& other); + + /// + /// Initialize with the given URI. + /// + /// @par Postconditions: + /// - `*this` is connected to the MongoDB server(s). + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL() client(v1::uri uri, options const& opts); + + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() client(v1::uri uri); + /// @} + /// + + /// + /// Initialize with default URI options. + /// + /// @par Postconditions: + /// - `*this` is connected to the MongoDB server(s). + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL() client(); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Return the URI options used to initialize this client. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::uri) uri() const; + + /// + /// Access the database with the given name. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::database) database(std::string name); + + /// + /// Equivalent to `this->database(name)`. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::database) operator[](std::string name); + + /// + /// Return an unsorted list of all existing databases. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`listDatabases` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/listdatabases/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list_databases(); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list_databases(v1::client_session const& session); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list_databases(bsoncxx::v1::document::view opts); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list_databases( + v1::client_session const& session, + bsoncxx::v1::document::view opts); + /// @} + /// + + /// + /// Return an unsorted list of the names of all existing databases. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`listDatabases` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/listdatabases/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(std::vector) list_database_names(bsoncxx::v1::document::view filter); + + MONGOCXX_ABI_EXPORT_CDECL(std::vector) list_database_names( + v1::client_session const& session, + bsoncxx::v1::document::view filter); + + MONGOCXX_ABI_EXPORT_CDECL(std::vector) list_database_names(); + + MONGOCXX_ABI_EXPORT_CDECL(std::vector) list_database_names(v1::client_session const& session); + /// @} + /// + + /// + /// Create a new client session to use with subsequent operations. + /// + /// @important The client session object MUST be passed as the first argument to all operations that are intended to + /// be executed in the context of a session. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Server Sessions (MongoDB Manual)](https://mongodb.com/docs/manual/reference/server-sessions/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::client_session) start_session(v1::client_session::options opts); + + MONGOCXX_ABI_EXPORT_CDECL(v1::client_session) start_session(); + /// @} /// - /// Options for @ref mongocxx::v1::client. + + /// + /// Return a change stream subscribed to this connection. + /// + /// @see + /// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch(v1::change_stream::options opts); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch(); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch( + v1::client_session const& session, + v1::change_stream::options opts); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch(v1::client_session const& session); + /// @} + /// + + /// + /// Return a change stream subscribed to this connection with events filtered/modified by `pipeline`. + /// + /// @see + /// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch( + v1::pipeline const& pipeline, + v1::change_stream::options const& opts); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) + watch(v1::client_session const& session, v1::pipeline const& pipeline, v1::change_stream::options const& opts); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch(v1::pipeline const& pipeline); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch(v1::client_session const& session, v1::pipeline const& pipeline); + /// @} + /// + + /// + /// Invalidate this client object without invaliding existing cursors or sessions. + /// + /// This function must be invoked by a (forked) child process to prevent its destruction within the child process + /// from invalidating the state of the client object within the parent process. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + /// @see + /// - [`mongoc_client_reset`](https://mongoc.org/libmongoc/current/mongoc_client_reset.html) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) reset(); +}; + +/// +/// Options for @ref mongocxx::v1::client. +/// +/// Supported fields include: +/// - `apm_opts` +/// - `auto_encryption_opts` +/// - `server_api_opts` +/// - `tls_opts` +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class client::options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Set the "tls_opts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) tls_opts(v1::tls v); + + /// + /// Return the current "tls_opts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_opts() const; + + /// + /// Set the "auto_encryption_opts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) auto_encryption_opts(v1::auto_encryption v); + + /// + /// Return the current "auto_encryption_opts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) auto_encryption_opts() const; + + /// + /// Set the "apm_opts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) apm_opts(v1::apm v); + + /// + /// Return the current "apm_opts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) apm_opts() const; + + /// + /// Set the "server_api_opts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) server_api_opts(v1::server_api v); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "server_api_opts" field. /// - class options {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) server_api_opts() const; }; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp index f071fb854f..bb9a4a5c81 100644 --- a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp @@ -20,6 +20,30 @@ #include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -29,6 +53,7 @@ namespace v1 { /// Provides interfaces to support both Queryable Encryption and Client-Side Field Level Encryption (CSFLE). /// /// @see +/// - [Client Side Encryption (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/client-side-encryption/client-side-encryption/) /// - [In-Use Encryption (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/csfle/) /// - [Queryable Encryption](https://www.mongodb.com/docs/manual/core/queryable-encryption/) /// - [CSFLE](https://www.mongodb.com/docs/manual/core/csfle/) @@ -36,12 +61,331 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class client_encryption { + private: + class impl; + std::unique_ptr _impl; + + public: + class options; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~client_encryption(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() client_encryption(client_encryption&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(client_encryption&) operator=(client_encryption&& other) noexcept; + + /// + /// This class is not copyable. + /// + client_encryption(client_encryption const& other); + + /// + /// This class is not copyable. + /// + client_encryption& operator=(client_encryption const& other); + + /// + /// Initialize with the given options. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() client_encryption(options const& opts); + + /// + /// Create a new data key within the key vault collection. + /// + /// @returns The new key document ID as a @ref bsoncxx::v1::types::binary_subtype::k_uuid. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::value) create_data_key( + bsoncxx::v1::stdx::string_view kms_provider, + v1::data_key const& opts); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::value) create_data_key(bsoncxx::v1::stdx::string_view kms_provider); + /// @} + /// + + /// + /// Create a collection with encrypted fields. + /// + /// @param db The database within which to create the encrypted collection. + /// @param name The name of the new encrypted collection. + /// @param opts "createCollection" options. + /// @param coll_opts Set to the options used to create the encrypted collection, including the "encryptedFields" + /// field. + /// @param kms_provider The KMS provider to use for this operation. + /// @param master_key The master key to use when creating a new data key. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::collection) create_encrypted_collection( + v1::database& db, + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view opts, + bsoncxx::v1::document::value& coll_opts, + bsoncxx::v1::stdx::string_view kms_provider, + bsoncxx::v1::document::view master_key); + + /// + /// Create a collection with encrypted fields. + /// + /// @param db The database within which to create the encrypted collection. + /// @param name The name of the new encrypted collection. + /// @param opts "createCollection" options. + /// @param coll_opts Set to the options used to create the encrypted collection, including the "encryptedFields" + /// field. + /// @param kms_provider The KMS provider to use for this operation. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::collection) create_encrypted_collection( + v1::database& db, + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view opts, + bsoncxx::v1::document::value& coll_opts, + bsoncxx::v1::stdx::string_view kms_provider); + + /// + /// Encrypt the given value. + /// + /// @returns The encrypted value as a @ref bsoncxx::v1::types::binary_subtype::k_encrypted. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::value) encrypt( + bsoncxx::v1::types::view value, + v1::encrypt const& opts); + + /// + /// Encrypt the given Match Expression or Aggregate Expression. + /// + /// @note This operation is only supported when the "queryType" field is "range" and the "algorithm" field is + /// "Range". + /// + /// @returns The encrypted expression. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) encrypt_expression( + bsoncxx::v1::document::view expr, + v1::encrypt const& opts); + + /// + /// Decrypt the given value. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::value) decrypt(bsoncxx::v1::types::view value); + + /// + /// Decrypt and (re-)encrypt multiple data keys. + /// + /// When the "masterKey" field is set, the data keys are are (re-)encrypted using the new "masterKey". Otherwise, + /// each data key is (re-)encrypted using their current "masterKey". + /// + /// All rewrapped data keys are updated in the key vault collection using a single bulk write operation. No bulk + /// write operation is executed when no data keys are found that match the given `filter`. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::rewrap_many_datakey_result) rewrap_many_datakey( + bsoncxx::v1::document::view filter, + v1::rewrap_many_datakey_options const& opts); + + /// + /// Delete the specified data key. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::delete_one_result) delete_key(bsoncxx::v1::types::value id); + + /// + /// Return the requested data key. + /// + /// @returns The raw server response. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) get_key(bsoncxx::v1::types::view id); + + /// + /// Return all data keys within the associated key vault collection. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) get_keys(); + + /// + /// Add a new keyAltName to the specified data key. + /// + /// @returns The data key before the addition of the new keyAltName. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) add_key_alt_name( + bsoncxx::v1::types::view id, + bsoncxx::v1::stdx::string_view key_alt_name); + + /// + /// Remove the specified data key. + /// + /// @returns The data key before its removal. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) remove_key_alt_name( + bsoncxx::v1::types::view id, + bsoncxx::v1::stdx::string_view key_alt_name); + + /// + /// Return the specified data key. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) get_key_by_alt_name( + bsoncxx::v1::stdx::string_view key_alt_name); +}; + +/// +/// Options for @ref mongocxx::v1::client_encryption. +/// +/// Supported fields include: +/// - `key_vault_client` ("keyVaultClient") +/// - `key_vault_namespace` ("keyVaultNamespace") +/// - `kms_providers` ("kmsProviders") +/// - `tls_opts` ("tlsOptions") +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class client_encryption::options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Set the "keyVaultClient" field. + /// + /// @important The associated client MUST outlive any client or pool configured to use this option. + /// + /// @param v Equivalent to "unset" when null. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) key_vault_client(mongocxx::v1::client* v); + + /// + /// Return the current "keyVaultClient" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) key_vault_client() const; + /// - /// Options for @ref mongocxx::v1::client_encryption. + /// The name of a database and a collection. + /// + /// ```cpp + /// ns_pair{"db", "coll"} // db.coll + /// ``` + /// + using ns_pair = std::pair; + + /// + /// Set the "keyVaultNamespace" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) key_vault_namespace(ns_pair v); + + /// + /// Return the current "keyVaultNamespace" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) key_vault_namespace() const; + + /// + /// Set the "kmsProviders" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) kms_providers(bsoncxx::v1::document::value v); + + /// + /// Return the current "kmsProviders" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) kms_providers() const; + + /// + /// Set the "tlsOptions" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) tls_opts(bsoncxx::v1::document::value v); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "tlsOptions" field. /// - class options {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_opts() const; }; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/client_session.hpp b/src/mongocxx/include/mongocxx/v1/client_session.hpp index 6ce2a1439f..8ad12c159a 100644 --- a/src/mongocxx/include/mongocxx/v1/client_session.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_session.hpp @@ -20,6 +20,20 @@ #include +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -33,12 +47,343 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class client_session { + private: + class impl; + std::unique_ptr _impl; + + public: + class options; + /// - /// Options for @ref mongocxx::v1::client_session. + /// The state of an associated transaction. /// /// @attention This feature is experimental! It is not ready for use! /// - class options {}; + enum class transaction_state { + /// + /// No associated transaction. + /// + k_transaction_none, + + /// + /// An associated transaction has started. + /// + k_transaction_starting, + + /// + /// The associated transaction is in progress. + /// + k_transaction_in_progress, + + /// + /// The associated transaction was committed. + /// + k_transaction_committed, + + /// + /// The associated transaction was aborted. + /// + k_transaction_aborted, + }; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views and references. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~client_session(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() client_session(client_session&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(client_session&) operator=(client_session&& other) noexcept; + + /// + /// This class is not copyable. + /// + client_session(client_session const&) = delete; + + /// + /// This class is not copyable. + /// + client_session& operator=(client_session const&) = delete; + + /// + /// Return the associated client object. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::client const&) client() const; + + /// + /// Return the options used to create this client session. + /// + MONGOCXX_ABI_EXPORT_CDECL(options) opts() const; + + /// + /// Return the current "lsid" (logical session ID). + /// + /// @returns Empty when one is not available. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) id() const; + + /// + /// Return this session's current "clusterTime" value. + /// + /// @returns Empty when not available. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) cluster_time() const; + + /// + /// Return this session's current "operationTime" value. + /// + /// @returns Default-initialized when not available. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::b_timestamp) operation_time() const; + + /// + /// Return the ID of the current pinned server. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint32_t) server_id() const; + + /// + /// Return the current transaction state. + /// + MONGOCXX_ABI_EXPORT_CDECL(transaction_state) get_transaction_state() const; + + /// + /// Return true when the current session is dirty. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) get_dirty() const; + + /// + /// Advance the "clusterTime" value for this session. + /// + /// @param v A "clusterTime" value obtained by a prior call to @ref cluster_time. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) advance_cluster_time(bsoncxx::v1::document::view v); + + /// + /// Advance the "operationTime" value for this session. + /// + /// @param v An "operationTime" value obtained by a prior call to @ref operation_time. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) advance_operation_time(bsoncxx::v1::types::b_timestamp v); + + /// + /// Start a new transaction using `opts` instead of default transaction options. + /// + /// @throws mongocxx::v1::exception when a client-side error is encountered. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) start_transaction(v1::transaction opts); + + /// + /// Start a new transaction. + /// + /// Default transaction options are applied to the new transaction. + /// + /// @throws mongocxx::v1::exception when a client-side error is encountered. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) start_transaction(); + + /// + /// Commit the current transaction. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) commit_transaction(); + + /// + /// Abort the current transaction. + /// + /// @throws mongocxx::v1::exception when a client-side error is encountered. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) abort_transaction(); + + /// + /// The callback function to invoke within a standalone transaction. + /// + /// `this` is passed to the callback function and must be forwarded to operations within the callback function. + /// + /// The callback function may be invoked multiple times as part of retry attempt behavior. + /// + /// @warning The callback function **MUST** allow any @ref mongocxx::v1::server_error exceptions thrown by an + /// operation within the callback function to propagate out of the callback function for correct retry attempt + /// behavior. The callback function **MUST NOT** attempt to manually retry operations. + /// + using with_transaction_cb = std::function; + + /// + /// Start and commit a new standalone transaction using `fn`. + /// + /// The behavior is approximately equivalent to: + /// ```cpp + /// this->start_transaction(opts); + /// while (/* unspecified */) { + /// try { + /// fn(); + /// this->commit_transaction(); // Success. + /// } catch (/* unspecified */) { + /// if (/* unspecified */) { + /// continue; // Retry attempt. + /// } else { + /// this->abort_transaction(); + /// throw; // Failure. + /// } + /// } + /// } + /// ``` + /// + /// Any user-defined exceptions thrown by `fn` will be caught and rethrown after the standalone transaction has been + /// aborted. + /// + /// @warning `fn` **MUST** allow any @ref mongocxx::v1::server_error exceptions thrown by an operation within `fn` + /// to propagate out of `fn` for correct retry attempt behavior. `fn` **MUST NOT** attempt to manually retry + /// operations. + /// + /// @note This operation uses an internal, non-configurable time limit of 120 seconds. The transaction may be + /// retried until this time limit is exceeded. + /// + /// @throws mongocxx::v1::exception when a client-side error is encountered. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and all retry attempts have failed. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) with_transaction(with_transaction_cb const& fn, v1::transaction const& opts); + + /// + /// Start and commit a new standalone transaction using `fn`. + /// + /// The default transaction options are applied to the new transaction. + /// + /// The behavior is approximately equivalent to: + /// ```cpp + /// this->start_transaction(); + /// while (/* unspecified */) { + /// try { + /// fn(); + /// this->commit_transaction(); // Success. + /// } catch (/* unspecified */) { + /// if (/* unspecified */) { + /// continue; // Retry attempt. + /// } else { + /// this->abort_transaction(); + /// throw; // Failure. + /// } + /// } + /// } + /// ``` + /// + /// Any user-defined exceptions thrown by `fn` will be caught and rethrown after the standalone transaction has been + /// aborted. + /// + /// @warning `fn` **MUST** allow any @ref mongocxx::v1::server_error exceptions thrown by an operation within `fn` + /// to propagate out of `fn` for correct retry attempt behavior. `fn` **MUST NOT** attempt to manually retry + /// operations. + /// + /// @note This operation uses an internal, non-configurable time limit of 120 seconds. The transaction may be + /// retried until this time limit is exceeded. + /// + /// @throws mongocxx::v1::exception when a client-side error is encountered. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and all retry attempts have failed. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) with_transaction(with_transaction_cb const& fn); +}; + +/// +/// Options for @ref mongocxx::v1::client_session. +/// +/// Supported fields include: +/// - `causal_consistency` ("causalConsistency") +/// - `snapshot` ("snapshot") +/// - `default_transaction_opts` ("defaultTransactionOptions") +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class client_session::options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Set the "causalConsistency" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) causal_consistency(bool v); + + /// + /// Return the current "causalConsistency" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) causal_consistency() const; + + /// + /// Set the "snapshot" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) snapshot(bool v); + + /// + /// Return the current "snapshot" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) snapshot() const; + + /// + /// Set the "defaultTransactionOptions" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) default_transaction_opts(v1::transaction v); + + /// + /// Return the current "defaultTransactionOptions" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) default_transaction_opts() const; }; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/collection.hpp b/src/mongocxx/include/mongocxx/v1/collection.hpp index 82acec22d3..3696a01fe3 100644 --- a/src/mongocxx/include/mongocxx/v1/collection.hpp +++ b/src/mongocxx/include/mongocxx/v1/collection.hpp @@ -1,5 +1,5 @@ -// Copyright 2009-present MongoDB, Inc. // +// Copyright 2009-present MongoDB, Inc. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -20,6 +20,51 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -31,11 +76,855 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class collection {}; +class collection { + private: + class impl; + std::unique_ptr _impl; + + template + using has_begin_expr = decltype((std::declval().begin())); + + template + struct has_begin : bsoncxx::detail::is_detected {}; + + template + using has_end_expr = decltype((std::declval().end())); + + template + struct has_end : bsoncxx::detail::is_detected {}; + + static void is_write_iter_expr_impl(v1::bulk_write::single) {} + + template + using is_write_iter_expr = decltype((is_write_iter_expr_impl)(*std::declval())); + + template + struct is_write_iter : bsoncxx::detail::is_detected {}; + + template + struct is_container : bsoncxx::detail::conjunction, has_end> {}; + + static void is_document_iter_expr_impl(bsoncxx::v1::document::view) {} + + template + using is_document_iter_expr = decltype((is_document_iter_expr_impl)(*std::declval())); + + template + struct is_document_iter : bsoncxx::detail::is_detected {}; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views, cursors, bulk writes, indexes, and change streams. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~collection(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() collection(collection&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(collection&) operator=(collection&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() collection(collection const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(collection&) operator=(collection const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() collection(); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Run an aggregation framework pipeline. + /// + /// @see + /// - [`aggregate` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/aggregate/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) aggregate( + v1::pipeline const& pipeline, + v1::aggregate_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) + aggregate(v1::client_session const& session, v1::pipeline const& pipeline, v1::aggregate_options const& opts = {}); + /// @} + /// + + /// + /// Create a bulk write operation. + /// + /// The bulk write operation must be executed with @ref mongocxx::v1::bulk_write::execute(). + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write) create_bulk_write(v1::bulk_write::options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write) create_bulk_write( + v1::client_session const& session, + v1::bulk_write::options const& opts = {}); + /// @} + /// + + /// + /// Equivalent to `this->bulk_write(...)` with a single write operation. + /// + /// @{ + bsoncxx::v1::stdx::optional write( + v1::bulk_write::single const& write, + v1::bulk_write::options const& opts = {}) { + return this->create_bulk_write(opts).append(write).execute(); + } + + bsoncxx::v1::stdx::optional write( + v1::client_session const& session, + v1::bulk_write::single const& write, + v1::bulk_write::options const& opts = {}) { + return this->create_bulk_write(session, opts).append(write).execute(); + } + /// @} + /// + + /// + /// Equivalent to `this->bulk_write(writes.begin(), writes.begin(), opts)`. + /// + /// @par Constraints: + /// - `writes.begin()` and `writes.end()` must be valid. + /// + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional bulk_write( + Container const& writes, + v1::bulk_write::options const& opts = {}) { + return this->bulk_write(writes.begin(), writes.end(), opts); + } + + /// + /// Equivalent to `this->bulk_write(session, writes.begin(), writes.begin(), opts)`. + /// + /// @par Constraints: + /// - `writes.begin()` and `writes.end()` must be valid. + /// + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional + bulk_write(v1::client_session const& session, Container const& writes, v1::bulk_write::options const& opts = {}) { + return this->bulk_write(session, writes.begin(), writes.end(), opts); + } + + /// + /// Execute multiple write operations. + /// + /// Equivalent to: + /// ```cpp + /// auto bulk = this->create_bulk_write(...); + /// for (auto iter = begin; iter != end; ++iter) { + /// bulk.append(*iter); + /// } + /// return bulk.execute(); + /// ``` + /// + /// @par Constraints: + /// - `InputIt` satisfies Cpp17InputIterator. + /// - The value type of `InputIt` is convertible to @ref mongocxx::v1::bulk_write::single. + /// + /// @see + /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// + /// @{ + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional + bulk_write(InputIt begin, InputIt end, v1::bulk_write::options const& opts = {}) { + v1::bulk_write bulk{this->create_bulk_write(opts)}; + for (auto iter = begin; iter != end; ++iter) { + bulk.append(*iter); + } + return bulk.execute(); + } + + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional bulk_write( + v1::client_session const& session, + InputIt begin, + InputIt end, + v1::bulk_write::options const& opts = {}) { + v1::bulk_write bulk{this->create_bulk_write(session, opts)}; + for (auto iter = begin; iter != end; ++iter) { + bulk.append(*iter); + } + return bulk.execute(); + } + /// @} + /// + + /// + /// Return the number of documents in this collection that match the given query filter. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) + /// - [`$group` (aggregation stage) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) count_documents( + bsoncxx::v1::document::view filter, + v1::count_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) + count_documents( + v1::client_session const& session, + bsoncxx::v1::document::view filter, + v1::count_options const& opts = {}); + /// @} + /// + + /// + /// Return an estimate of the number of documents in this collection using collection metadata. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) + /// - [`count` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/count/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) estimated_document_count( + v1::estimated_document_count_options const& opts = {}); + + /// + /// Equivalent to `this->indexes().create_one(...)`. + /// + /// @{ + bsoncxx::v1::stdx::optional create_index( + bsoncxx::v1::document::value keys, + bsoncxx::v1::document::value create_opts = {}, + v1::indexes::options opts = {}) { + return this->indexes().create_one(keys, create_opts, opts); + } + + bsoncxx::v1::stdx::optional create_index( + v1::client_session const& session, + bsoncxx::v1::document::value keys, + bsoncxx::v1::document::value create_opts = {}, + v1::indexes::options opts = {}) { + return this->indexes().create_one(session, keys, create_opts, opts); + } + /// @} + /// + + /// + /// Delete multiple documents in this collection using the given query filter. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`delete` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/delete/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) delete_many( + bsoncxx::v1::document::view q, + v1::delete_many_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) delete_many( + v1::client_session const& session, + bsoncxx::v1::document::view q, + v1::delete_many_options const& opts = {}); + /// @} + /// + + /// + /// Delete a single document in this collection using the given query filter. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`delete` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/delete/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) delete_one( + bsoncxx::v1::document::view q, + v1::delete_one_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + delete_one( + v1::client_session const& session, + bsoncxx::v1::document::view q, + v1::delete_one_options const& opts = {}); + /// @} + /// + + /// + /// Return the distinct values for the specified field within this collection. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`distinct` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/distinct/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) + distinct( + bsoncxx::v1::stdx::string_view key, + bsoncxx::v1::document::view query, + v1::distinct_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) distinct( + v1::client_session const& session, + bsoncxx::v1::stdx::string_view key, + bsoncxx::v1::document::view query, + v1::distinct_options const& opts = {}); + /// @} + /// + + /// + /// Drop this collection. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`drop` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/atlas/data-federation/admin/cli/collections/drop-collections-views/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(void) drop( + bsoncxx::v1::stdx::optional wc = {}, + bsoncxx::v1::document::view opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(void) drop( + v1::client_session const& session, + bsoncxx::v1::stdx::optional wc = {}, + bsoncxx::v1::document::view opts = {}); + /// @} + /// + + /// + /// Find documents in this collection matching the given query filter. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::collection::errc::max_await_time_u32 if the + /// "maxAwaitTimeMS" field is not representable as an `std::uint32_t`. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`find` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/find/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) find(bsoncxx::v1::document::view filter, v1::find_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) + find(v1::client_session const& session, bsoncxx::v1::document::view filter, v1::find_options const& opts = {}); + /// @} + /// + + /// + /// Return the first matching document obtained by `this->find(...)`. + /// + /// @returns Empty when no matching document was found. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::collection::errc::max_await_time_u32 if the + /// "maxAwaitTimeMS" field is not representable as an `std::uint32_t`. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`find` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/find/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one( + bsoncxx::v1::document::view filter, + v1::find_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + find_one(v1::client_session const& session, bsoncxx::v1::document::view filter, v1::find_options const& opts = {}); + /// @} + /// + + /// + /// Find a single document in this collection and delete it, returning the original document. + /// + /// @returns Empty when no matching document was found. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`findAndModify` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/findAndModify/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_delete( + bsoncxx::v1::document::view query, + v1::find_one_and_delete_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_delete( + v1::client_session const& session, + bsoncxx::v1::document::view query, + v1::find_one_and_delete_options const& opts = {}); + /// @} + /// + + /// + /// Find a single document in this collection and replace it. + /// + /// @returns The document before or after replacement, depending on the "returnDocument" field. Empty when no + /// matching document was found. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`findAndModify` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/findAndModify/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_replace( + bsoncxx::v1::document::view query, + bsoncxx::v1::document::value replacement, + v1::find_one_and_replace_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_replace( + v1::client_session const& session, + bsoncxx::v1::document::view query, + bsoncxx::v1::document::value update, + v1::find_one_and_replace_options const& opts = {}); + /// @} + /// + + /// + /// Find a single document in this collection and update it. + /// + /// @returns The document before or after the update, depending on the "returnDocument" field. Empty when no + /// matching document was found. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`findAndModify` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/findAndModify/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + bsoncxx::v1::document::view query, + bsoncxx::v1::document::view update, + v1::find_one_and_update_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + bsoncxx::v1::document::view query, + v1::pipeline const& update, + v1::find_one_and_update_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + v1::client_session const& session, + bsoncxx::v1::document::view query, + bsoncxx::v1::document::view update, + v1::find_one_and_update_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + v1::client_session const& session, + bsoncxx::v1::document::view query, + v1::pipeline const& update, + v1::find_one_and_update_options const& opts = {}); + /// @} + /// + + /// + /// Insert a single document into this collection as a bulk write operation. + /// + /// If the document(s) do not contain an "_id" field, an "_id" field is generated using @ref bsoncxx::v1::oid. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) insert_one( + bsoncxx::v1::document::view document, + v1::insert_one_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) insert_one( + v1::client_session const& session, + bsoncxx::v1::document::view document, + v1::insert_one_options const& opts = {}); + /// @} + /// + + /// + /// Equivalent to `this->insert_many(docs.begin(), docs.end(), opts)`. + /// + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional insert_many( + Container const& docs, + v1::insert_many_options const& opts = {}) { + return this->insert_many(docs.begin(), docs.end(), opts); + } + + /// + /// Equivalent to `this->insert_many(session, docs.begin(), docs.end(), opts)`. + /// + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional + insert_many(v1::client_session const& session, Container const& docs, v1::insert_many_options const& opts = {}) { + return this->insert_many(session, docs.begin(), docs.end(), opts); + } + + /// + /// Insert the given documents into this collection as a bulk write operation. + /// + /// If the document(s) do not contain an "_id" field, an "_id" field is generated using @ref bsoncxx::v1::oid. + /// + /// @par Constraints: + /// - `InputIt` satisfies Cpp17InputIterator. + /// - The value type of `InputIt` is convertible to @ref bsoncxx::v1::document::view. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// + /// @{ + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional + insert_many(InputIt begin, InputIt end, v1::insert_many_options const& opts = {}) { + v1::bulk_write bulk{this->_create_insert_many(nullptr, opts)}; + std::vector inserted_ids; + for (auto iter = begin; iter != end; ++iter) { + this->_append_insert_many(bulk, inserted_ids, *iter); + } + return this->_execute_insert_many(bulk, inserted_ids); + } + + template ::value>* = nullptr> + bsoncxx::v1::stdx::optional insert_many( + v1::client_session const& session, + InputIt begin, + InputIt end, + v1::insert_many_options const& opts = {}) { + v1::bulk_write bulk{this->_create_insert_many(&session, opts)}; + std::vector inserted_ids; + for (auto iter = begin; iter != end; ++iter) { + this->_append_insert_many(bulk, inserted_ids, *iter); + } + return this->_execute_insert_many(bulk, inserted_ids); + } + /// @} + /// + + /// + /// Equivalent to `this->indexes.list()`. + /// + v1::cursor list_indexes() { + return this->indexes().list(); + } + + /// + /// Equivalent to `this->indexes.list(session)`. + /// + v1::cursor list_indexes(v1::client_session const& session) { + return this->indexes().list(session); + } + + /// + /// Return the name of this collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) name() const; + + /// + /// Change the name of this collection. + /// + /// @throws mongocxx::v1::exception when a client-side or server-side error is encountered. (mongoc does not return + /// the raw server response for this command.) + /// + /// @see + /// - [`renameCollection` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/renamecollection/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(void) rename( + bsoncxx::v1::stdx::string_view new_name, + bool drop_target = false, + bsoncxx::v1::stdx::optional write_concern = {}); + + MONGOCXX_ABI_EXPORT_CDECL(void) rename( + v1::client_session const& session, + bsoncxx::v1::stdx::string_view new_name, + bool drop_target = false, + bsoncxx::v1::stdx::optional write_concern = {}); + /// @} + /// + + /// + /// Set the default "readConcern" to use for operations on this collection. + /// + /// Overrides the default inherited from the associated database or client. May be overridden by individual + /// operations. + /// + /// @see + /// - [Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) read_concern(v1::read_concern rc); + + /// + /// Return the current default "readConcern" to use for operations on this collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::read_concern) read_concern() const; + + /// + /// Set the default "readPreference" to use for operations on this collection. + /// + /// Overrides the default inherited from the associated database or client. May be overridden by individual + /// operations. + /// + /// @see + /// - [Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) read_preference(v1::read_preference rp); + + /// + /// Return the current default "readPreference" to use for operations on this collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::read_preference) read_preference() const; + + /// + /// Replace a single document in this collection as a bulk write operation. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) replace_one( + bsoncxx::v1::document::view filter, + bsoncxx::v1::document::value replacement, + v1::replace_one_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) replace_one( + v1::client_session const& session, + bsoncxx::v1::document::view filter, + bsoncxx::v1::document::value replacement, + v1::replace_one_options const& opts = {}); + /// @} + /// + + /// + /// Update multiple documents in this collection as a bulk write operation. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) update_many( + bsoncxx::v1::document::view filter, + bsoncxx::v1::document::view update, + v1::update_many_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + update_many(bsoncxx::v1::document::view filter, v1::pipeline const& update, update_many_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) update_many( + v1::client_session const& session, + bsoncxx::v1::document::view filter, + bsoncxx::v1::document::view update, + v1::update_many_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) update_many( + v1::client_session const& session, + bsoncxx::v1::document::view filter, + v1::pipeline const& update, + v1::update_many_options const& opts = {}); + /// @} + /// + + /// + /// Update multiple documents in this collection as a bulk write operation. + /// + /// @returns Empty when the bulk write operation is unacknowledged. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) update_one( + bsoncxx::v1::document::view filter, + bsoncxx::v1::document::view update, + v1::update_one_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + update_one(bsoncxx::v1::document::view filter, v1::pipeline const& update, update_one_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) update_one( + v1::client_session const& session, + bsoncxx::v1::document::view filter, + bsoncxx::v1::document::view update, + v1::update_one_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) update_one( + v1::client_session const& session, + bsoncxx::v1::document::view filter, + v1::pipeline const& update, + v1::update_one_options const& opts = {}); + /// @} + /// + + /// + /// Set the default "writeConcern" to use for operations on this collection. + /// + /// Overrides the default inherited from the associated database or client. May be overridden by individual + /// operations. + /// + /// @see + /// - [Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) write_concern(v1::write_concern wc); + + /// + /// Return the current default "writeConcern" to use for operations on this collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::write_concern) write_concern() const; + + /// + /// Manage indexes associated with this collection. + /// + /// @see + /// - [Indexes (MongoDB Manual)](https://www.mongodb.com/docs/manual/indexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::indexes) indexes(); + + /// + /// Return a change stream subscribed to this collection. + /// + /// @see + /// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch(v1::change_stream::options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch( + v1::client_session const& session, + v1::change_stream::options const& opts = {}); + /// @} + /// + + /// + /// Return a change stream subscribed to this collection with events filtered/modified by `pipeline`. + /// + /// @see + /// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch( + v1::pipeline const& pipeline, + v1::change_stream::options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) + watch(v1::client_session const& session, v1::pipeline const& pipeline, v1::change_stream::options const& opts = {}); + /// @} + /// + + /// + /// Manage Atlas Search Indexes associated with this collection. + /// + /// @see + /// - [Manage MongoDB Search Indexes (MongoDB Manual)](https://www.mongodb.com/docs/atlas/atlas-search/manage-indexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::search_indexes) search_indexes(); + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::collection. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + max_await_time_u32, ///< The "maxAwaitTimeMS" field must be representable as an `std::uint32_t`. + }; + + /// + /// The error category for @ref mongocxx::v1::collection::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } + + private: + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write) _create_insert_many( + v1::client_session const* session, + v1::insert_many_options const& opts); + + static MONGOCXX_ABI_EXPORT_CDECL(void) _append_insert_many( + v1::bulk_write& bulk, + std::vector& inserted_ids, + bsoncxx::v1::document::view doc); + + static MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) _execute_insert_many( + v1::bulk_write& bulk, + std::vector& inserted_ids); +}; } // namespace v1 } // namespace mongocxx +namespace std { + +template <> +struct is_error_code_enum : true_type {}; + +} // namespace std + #include /// diff --git a/src/mongocxx/include/mongocxx/v1/count_options.hpp b/src/mongocxx/include/mongocxx/v1/count_options.hpp index 4bda3df162..cc5142ccc3 100644 --- a/src/mongocxx/include/mongocxx/v1/count_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/count_options.hpp @@ -20,18 +20,159 @@ #include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for a "countDocuments" operation. /// +/// Supported fields include: +/// - `collation` +/// - `comment` +/// - `hint` +/// - `limit` +/// - `max_time` ("maxTimeMS") +/// - `read_preference` ("readPreference") +/// - `skip` +/// /// @see /// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) /// /// @attention This feature is experimental! It is not ready for use! /// -class count_options {}; +class count_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~count_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() count_options(count_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) operator=(count_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() count_options(count_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) operator=(count_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() count_options(); + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; + + /// + /// Set the "limit" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) limit(std::int64_t limit); + + /// + /// Return the current "limit" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) limit() const; + + /// + /// Set the "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "skip" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) skip(std::int64_t skip); + + /// + /// Return the current "skip" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) skip() const; + + /// + /// Set the "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(count_options&) read_preference(v1::read_preference rp); + + /// + /// Return the current "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_preference() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/cursor.hpp b/src/mongocxx/include/mongocxx/v1/cursor.hpp index 80bde5ac66..dc93d4d847 100644 --- a/src/mongocxx/include/mongocxx/v1/cursor.hpp +++ b/src/mongocxx/include/mongocxx/v1/cursor.hpp @@ -20,6 +20,14 @@ #include +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +39,230 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class cursor {}; +class cursor { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Enumeration identifying the type of the cursor. + /// + enum class type { + /// + /// [A non-tailable + /// cursor](https://specifications.readthedocs.io/en/latest/client-side-operations-timeout/client-side-operations-timeout/). + /// + k_non_tailable, + + /// + /// [A tailable + /// cursor](https://specifications.readthedocs.io/en/latest/client-side-operations-timeout/client-side-operations-timeout/). + /// + k_tailable, + + /// + /// [A tailable "awaitData" + /// cursor](https://specifications.readthedocs.io/en/latest/client-side-operations-timeout/client-side-operations-timeout/). + /// + k_tailable_await, + }; + + class iterator; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views and iterators. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~cursor(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() cursor(cursor&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(cursor&) operator=(cursor&& other) noexcept; + + /// + /// This class is not copyable. + /// + cursor(cursor const&) = delete; + + /// + /// This class is not copyable. + /// + cursor& operator=(cursor const&) = delete; + + /// + /// Return an iterator over the results of the associated query. + /// + /// @important All iterators associated with the same cursor object share the same state. + /// + /// This function advances the underlying cursor to obtain the next (first) result document. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator) begin(); + + /// + /// Return an end iterator. + /// + /// @important The end iterator has no associated query. + /// + iterator end() const; +}; + +/// +/// An iterator over the results of an associated cursor. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +/// @important All iterators associated with the same cursor object share the same state. +/// @important The end iterator has no associated cursor. +/// +/// @note This iterator almost satisfies Cpp17ForwardIterator, but `std::iterator_traits::reference` is defined as +/// `value_type`, similar to `std::vector::iterator` and `std::istreambuf_iterator`. Therefore, this iterator +/// only fully satisfies Cpp17InputIterator. +/// +/// @see +/// - [Cursors (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/cursors/) +/// +class cursor::iterator { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Provide `std::iterator_traits::iterator_category`. + /// + using iterator_category = std::input_iterator_tag; + + /// + /// Provide `std::iterator_traits::value_type`. + /// + using value_type = bsoncxx::v1::document::view; + + /// + /// Provide `std::iterator_traits::difference_type`. + /// + using difference_type = std::ptrdiff_t; + + /// + /// Provide `std::iterator_traits::pointer`. + /// + using pointer = value_type const*; + + /// + /// Provide `std::iterator_traits::reference`. + /// + using reference = value_type; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~iterator(); + + /// + /// Move construction. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() iterator(iterator&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator&) operator=(iterator&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() iterator(iterator const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator&) operator=(iterator const& other); + + /// + /// Initialize as an end iterator. + /// + MONGOCXX_ABI_EXPORT_CDECL() iterator(); + + /// + /// Access the current query result document. + /// + MONGOCXX_ABI_EXPORT_CDECL(value_type) operator*() const; + + /// + /// Access the current result document. + /// + /// @par Preconditions: + /// - `*this` does not compare equal to the end iterator. + /// + /// @returns Empty when there is no result document available. + /// + MONGOCXX_ABI_EXPORT_CDECL(pointer) operator->() const; + + /// + /// Increment this iterator. + /// + /// Advance the underlying cursor to obtain the next result document. + /// Compare equal to the end iterator when there are no result documents available. + /// + /// @note Pre-increment and post-increment are equivalent. + /// + /// @warning Invalidates all views to the current result document. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(iterator&) operator++(); + + /// @copydoc operator++() + iterator& operator++(int) { + return this->operator++(); + } + + /// + /// Equality comparison. + /// + /// `lhs` and `rhs` compare equal when: + /// - both are associated with the same cursor object, or + /// - both are end iterators, or + /// - one is an end iterator and the other has no result document available. + /// + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(iterator const& lhs, iterator const& rhs); + + /// + /// Equivalent to `!(lhs == rhs)`. + /// + friend bool operator!=(iterator const& lhs, iterator const& rhs) { + return !(lhs == rhs); + } +}; + +inline cursor::iterator cursor::end() const { + return {}; +} } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/data_key.hpp b/src/mongocxx/include/mongocxx/v1/data_key.hpp index 487084b661..a8e25b9559 100644 --- a/src/mongocxx/include/mongocxx/v1/data_key.hpp +++ b/src/mongocxx/include/mongocxx/v1/data_key.hpp @@ -20,18 +20,116 @@ #include +#include +#include + +#include + +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// A Data Encryption Key (DEK) for In-Use Encryption. /// +/// Supported fields include: +/// - `key_alt_names` ("keyAltNames") +/// - `key_material` ("keyMaterial") +/// - `master_key` ("masterKey") +/// /// @see /// - [Encryption Keys and Key Vaults (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/keys-key-vaults/) /// /// @attention This feature is experimental! It is not ready for use! /// -class data_key {}; +class data_key { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~data_key(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() data_key(data_key&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key&) operator=(data_key&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() data_key(data_key const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key&) operator=(data_key const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() data_key(); + + /// + /// Set the "masterKey" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key&) master_key(bsoncxx::v1::document::value master_key); + + /// + /// Return the current "masterKey" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) master_key() const; + + /// + /// Set the "keyAltNames" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key&) key_alt_names(std::vector key_alt_names); + + /// + /// Return the current "keyAltNames" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::vector) key_alt_names() const; + + /// + /// Binary data with a length of exactly 96 bytes. + /// + using key_material_type = std::vector; + + /// + /// Set the "keyMaterial" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key&) key_material(key_material_type key_material); + + /// + /// Return the current "keyMaterial" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) key_material(); +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/database.hpp b/src/mongocxx/include/mongocxx/v1/database.hpp index 1d16cdfd50..8e6d9c6645 100644 --- a/src/mongocxx/include/mongocxx/v1/database.hpp +++ b/src/mongocxx/include/mongocxx/v1/database.hpp @@ -20,6 +20,28 @@ #include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +53,296 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class database {}; +class database { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views, collections, cursors, GridFS buckets, and change streams. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~database(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() database(database&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(database&) operator=(database&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() database(database const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(database&) operator=(database const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() database(); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Run an aggregation framework pipeline. + /// + /// @see + /// - [`aggregate` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/aggregate/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) aggregate( + v1::pipeline const& pipeline, + v1::aggregate_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) + aggregate(v1::client_session const& session, v1::pipeline const& pipeline, v1::aggregate_options const& opts = {}); + /// @} + /// + + /// + /// Run an arbitrary database command. + /// + /// @returns The raw server response. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Database Commands](https://www.mongodb.com/docs/manual/reference/command/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) run_command(bsoncxx::v1::document::view command); + + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) run_command( + v1::client_session const& session, + bsoncxx::v1::document::view command); + /// @} + /// + + /// + /// Run an arbitrary database command against the requested specific server. + /// + /// @returns The raw server response. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [Database Commands](https://www.mongodb.com/docs/manual/reference/command/) + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) run_command( + bsoncxx::v1::document::view command, + std::uint32_t server_id); + + /// + /// Explicitly create a new collection or view in this database. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`create` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/create/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::collection) create_collection( + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view opts = {}, + bsoncxx::v1::stdx::optional wc = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::collection) create_collection( + v1::client_session const& session, + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view opts = {}, + bsoncxx::v1::stdx::optional wc = {}); + /// @} + /// + + /// + /// Drop this database and all associated data files. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`dropDatabase` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/dropDatabase/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(void) drop(bsoncxx::v1::stdx::optional wc = {}); + + MONGOCXX_ABI_EXPORT_CDECL(void) drop( + v1::client_session const& session, + bsoncxx::v1::stdx::optional wc = {}); + /// @} + /// + + /// + /// Return true when this database contains a collection with the given name. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) has_collection(bsoncxx::v1::stdx::string_view name) const; + + /// + /// Return an unsorted list of all collections and views in this database. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`listCollections` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/listCollections/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list_collections(bsoncxx::v1::document::view filter = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list_collections( + v1::client_session const& session, + bsoncxx::v1::document::view filter = {}); + /// @} + /// + + /// + /// Return an unsorted list of the names of all the collections and views in this database. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`listCollections` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/listCollections/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(std::vector) list_collection_names(bsoncxx::v1::document::view filter = {}); + + MONGOCXX_ABI_EXPORT_CDECL(std::vector) list_collection_names( + v1::client_session const& session, + bsoncxx::v1::document::view filter = {}); + /// @} + /// + + /// + /// Return the name of this database. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) name() const; + + /// + /// Set the default "readConcern" to use for operations on this database. + /// + /// Overrides the default inherited from the associated client. May be overridden by individual operations. + /// + /// @see + /// - [Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) read_concern(v1::read_concern rc); + + /// + /// Return the current default "readConcern" to use for operations on this database. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::read_concern) read_concern() const; + + /// + /// Set the default "readPreference" to use for operations on this database. + /// + /// Overrides the default inherited from the associated client. May be overridden by individual operations. + /// + /// @see + /// - [Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) read_preference(v1::read_preference rp); + + /// + /// Return the current default "readPreference" to use for operations on this database. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::read_preference) read_preference() const; + + /// + /// Set the default "writeConcern" to use for operations on this database. + /// + /// Overrides the default inherited from the associated client. May be overridden by individual operations. + /// + /// @see + /// - [Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) write_concern(v1::write_concern wc); + + /// + /// Return the current default "writeConcern" to use for operations on this database. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::write_concern) write_concern() const; + + /// + /// Access the collection with the given name. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::collection) collection(bsoncxx::v1::stdx::string_view name) const; + + /// + /// Equivalent to `this->collection(name)`. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::collection) operator[](bsoncxx::v1::stdx::string_view name) const; + + /// + /// Return a GridFS bucket for this database. + /// + /// @note When the "bucketName" field is unset, the default bucket name "fs" is used instead. + /// @note When the "chunkSizeBytes" field is unset, the default chunk size of 255 kB is used instead. + /// + /// @see + /// - [GridFS (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/gridfs/) + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::bucket) gridfs_bucket(v1::gridfs::bucket::options const& opts = {}) const; + + /// + /// Return a change stream subscribed to this database. + /// + /// @see + /// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch(v1::change_stream::options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch( + v1::client_session const& session, + v1::change_stream::options const& opts = {}); + /// @} + /// + + /// + /// Return a change stream subscribed to this collection with events filtered/modified by `pipeline`. + /// + /// @see + /// - [Change Streams (MongoDB Manual)](https://www.mongodb.com/docs/manual/changeStreams/) + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch( + v1::pipeline const& pipe, + v1::change_stream::options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) + watch(v1::client_session const& session, v1::pipeline const& pipe, v1::change_stream::options const& opts = {}); + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp b/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp index 486ab411c8..c35bdd0973 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp @@ -20,18 +20,135 @@ #include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for a "deleteMany" operation. /// +/// Supported fields include: +/// - `collation` +/// - `hint` +/// - `let` +/// - `write_concern` ("writeConcern") +/// - comment` +/// /// @see /// - [Delete Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/delete-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class delete_many_options {}; +class delete_many_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~delete_many_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many_options(delete_many_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_options&) operator=(delete_many_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many_options(delete_many_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_options&) operator=(delete_many_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many_options(); + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_options&) write_concern(write_concern wc); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp b/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp index b46434a78b..139bbc98cf 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp @@ -20,18 +20,83 @@ #include +#include +#include + +#include + namespace mongocxx { namespace v1 { /// -/// The result of a "deleteMany" operation. +/// The result of a "deleteOne" operation. /// /// @see /// - [Delete Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/delete-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class delete_many_result {}; +class delete_many_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~delete_many_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many_result(delete_many_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_result&) operator=(delete_many_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many_result(delete_many_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many_result&) operator=(delete_many_result const& other); + + /// + /// Return the raw bulk write result. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; + + /// + /// Return the number of documents that were deleted. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) deleted_count() const; + + /// + /// Compare equal when `lhs.result()` and `rhs.result()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(delete_many_result const& lhs, delete_many_result const& rhs); + + friend bool operator!=(delete_many_result const& lhs, delete_many_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp b/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp index 022c67ce39..c224bd0831 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp @@ -20,18 +20,135 @@ #include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for a "deleteOne" operation. /// +/// Supported fields include: +/// - `collation` +/// - `hint` +/// - `let` +/// - `write_concern` ("writeConcern") +/// - comment` +/// /// @see /// - [Delete Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/delete-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class delete_one_options {}; +class delete_one_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~delete_one_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one_options(delete_one_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) operator=(delete_one_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one_options(delete_one_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) operator=(delete_one_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one_options(); + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) write_concern(write_concern wc); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp b/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp index 94d0f70837..f75cc3737f 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp @@ -20,6 +20,11 @@ #include +#include +#include + +#include + namespace mongocxx { namespace v1 { @@ -31,7 +36,67 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class delete_one_result {}; +class delete_one_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~delete_one_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one_result(delete_one_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_result&) operator=(delete_one_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one_result(delete_one_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one_result&) operator=(delete_one_result const& other); + + /// + /// Return the raw bulk write result. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; + + /// + /// Return the number of documents that were deleted. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) deleted_count() const; + + /// + /// Compare equal when `lhs.result()` and `rhs.result()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(delete_one_result const& lhs, delete_one_result const& rhs); + + friend bool operator!=(delete_one_result const& lhs, delete_one_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/detail/macros.hpp b/src/mongocxx/include/mongocxx/v1/detail/macros.hpp index 1e50fa51e0..8e841be843 100644 --- a/src/mongocxx/include/mongocxx/v1/detail/macros.hpp +++ b/src/mongocxx/include/mongocxx/v1/detail/macros.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Traditional include guard is required to support v_noabi include-via-prelude. +// Traditional include guard is required to support v1 include-via-prelude. #if !defined(MONGOCXX_V1_DETAIL_MACROS_HPP) #define MONGOCXX_V1_DETAIL_MACROS_HPP diff --git a/src/mongocxx/include/mongocxx/v1/distinct_options.hpp b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp index ea9da71e30..5fecaf01b1 100644 --- a/src/mongocxx/include/mongocxx/v1/distinct_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp @@ -20,16 +20,122 @@ #include +#include +#include +#include +#include + +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for a "distinct" command. /// +/// Supported fields include: +/// - `collation` +/// - `comment` +/// - `max_time` ("maxTimeMS") +/// - `read_preference` ("readPreference") +/// /// @see /// - [`distinct` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/distinct/) /// -class distinct_options {}; +class distinct_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~distinct_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() distinct_options(distinct_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(distinct_options&) operator=(distinct_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() distinct_options(distinct_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(distinct_options&) operator=(distinct_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() distinct_options(); + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(distinct_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "maxTime" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(distinct_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTime" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(distinct_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; + + /// + /// Set the "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(distinct_options&) read_preference(v1::read_preference rp); + + /// + /// Return the current "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_preference() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/encrypt.hpp b/src/mongocxx/include/mongocxx/v1/encrypt.hpp index a956b70774..11758909d9 100644 --- a/src/mongocxx/include/mongocxx/v1/encrypt.hpp +++ b/src/mongocxx/include/mongocxx/v1/encrypt.hpp @@ -20,12 +20,34 @@ #include +#include +#include + +#include + +#include +#include + +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to explicit encryption for In-Use Encryption. /// +/// Supported fields include: +/// - `algorithm` +/// - `contention_factor` ("contentionFactor") +/// - `key_alt_name` ("keyAltName") +/// - `key_id` ("keyId") +/// - `query_type` ("queryType") +/// - `range_opts` ("rangeOpts") +/// /// @see /// - [Fields and Encryption Types (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/csfle/fundamentals/encryption-algorithms/) /// - [Encrypted Fields and Enabled Queries (MongoDB Manual)](https://mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/) @@ -36,6 +58,139 @@ namespace v1 { class encrypt { // This class implements `EncryptOpts`: // - https://specifications.readthedocs.io/en/latest/client-side-encryption/client-side-encryption/ + + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// An encryption algorithm. + /// + /// @see + /// - [Fields and Encryption Types (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/csfle/fundamentals/encryption-algorithms/) + /// + enum class encryption_algorithm : std::uint8_t { + k_deterministic, ///< "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" + k_random, ///< "AEAD_AES_256_CBC_HMAC_SHA_512-Random" + k_indexed, ///< "Indexed" + k_unindexed, ///< "Unindexed" + k_range, ///< "Range" + }; + + /// + /// A query type. + /// + /// @see + /// - [Supported Operations for Queryable Encryption (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/supported-operations/) + /// + enum class encryption_query_type : std::uint8_t { + k_equality, ///< "equalty" + k_range, ///< "range" + }; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~encrypt(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() encrypt(encrypt&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) operator=(encrypt&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() encrypt(encrypt const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) operator=(encrypt const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() encrypt(); + + /// + /// Set the "keyId" field. + /// + /// @param v A @ref bsoncxx::v1::types::binary_subtype::k_uuid. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) key_id(bsoncxx::v1::types::value v); + + /// + /// Return the current "keyId" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) key_id() const; + + /// + /// Set the "keyAltName" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) key_alt_name(std::string v); + + /// + /// Return the "keyAltName" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) key_alt_name() const; + + /// + /// Set the "algorithm" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) algorithm(encryption_algorithm v); + + /// + /// Return the current "algorithm" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) algorithm() const; + + /// + /// Set the "contentionFactor" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) contention_factor(std::int64_t v); + + /// + /// Return the current "contentionFactor" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) contention_factor() const; + + /// + /// Set the "queryType" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) query_type(encryption_query_type v); + + /// + /// Return the current "queryType" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) query_type() const; + + /// + /// Set the "rangeOpts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt&) range_opts(v1::range v); + + /// + /// Return the current "rangeOpts" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) range_opts() const; }; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp b/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp index a5006e761a..3c152a9f64 100644 --- a/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp @@ -20,17 +20,112 @@ #include +#include +#include + +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for an "estimatedDocumentCount" operation. /// +/// Supported fields include: +/// - `comment` +/// - `max_time` ("maxTimeMS") +/// - `read_preference` ("readPreference") +/// /// @see /// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) /// - [`count` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/count/) /// -class estimated_document_count_options {}; +class estimated_document_count_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~estimated_document_count_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() estimated_document_count_options(estimated_document_count_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count_options&) operator=( + estimated_document_count_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() estimated_document_count_options(estimated_document_count_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count_options&) operator=( + estimated_document_count_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() estimated_document_count_options(); + + /// + /// Set the "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; + + /// + /// Set the "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(estimated_document_count_options&) read_preference(v1::read_preference rp); + + /// + /// Return the current "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_preference() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp b/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp index c0ec2f898d..89c9ae9e21 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp @@ -20,6 +20,17 @@ #include +#include +#include + +#include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +43,54 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class command_failed {}; +class command_failed { + private: + void const* _impl; // mongoc_apm_command_failed_t const* + + public: + /// + /// Return the failure document. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) failure() const; + + /// + /// Return the command name. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) command_name() const; + + /// + /// Return the execution time of the event. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) duration() const; + + /// + /// Return the client-generated request ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) request_id() const; + + /// + /// Return the client-generated operation ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) operation_id() const; + + /// + /// Return the service ID for the command (when in load balancer mode). + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) service_id() const; + + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + private: + /* explicit(false) */ command_failed(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/command_started.hpp b/src/mongocxx/include/mongocxx/v1/events/command_started.hpp index a5f9c41d37..17a5522363 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_started.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_started.hpp @@ -20,6 +20,17 @@ #include +#include +#include + +#include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +43,54 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class command_started {}; +class command_started { + private: + void const* _impl; // mongoc_apm_command_started_t const* + + public: + /// + /// Return the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) command() const; + + /// + /// Return the database name. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) database_name() const; + + /// + /// Return the command name. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) command_name() const; + + /// + /// Return the client-generated request ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) request_id() const; + + /// + /// Return the cklient-generated operation ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) operation_id() const; + + /// + /// Return the service ID for the command (when in load balancer mode). + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) service_id() const; + + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + private: + /* explicit(false) */ command_started(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp b/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp index 534e3763c0..4c287d3712 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp @@ -20,6 +20,16 @@ #include +#include +#include + +#include +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +42,54 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class command_succeeded {}; +class command_succeeded { + private: + void const* _impl; // mongoc_apm_command_succeeded_t const* + + public: + /// + /// Return the command reply. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) reply() const; + + /// + /// Return the command name. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) command_name() const; + + /// + /// Return the execution time of the event. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) duration() const; + + /// + /// Return the client-generated request ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) request_id() const; + + /// + /// Return the client-generated operation ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) operation_id() const; + + /// + /// Return the service ID for the command (when in load balancer mode). + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) service_id() const; + + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + private: + /* explicit(false) */ command_succeeded(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp index c3a04e4411..7fff29a024 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +41,29 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_closed {}; +class server_closed { + private: + void const* _impl; // mongoc_apm_server_closed_t const* + + public: + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + /// + /// Return the client-generated unique topology ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::oid) topology_id() const; + + private: + /* explicit(false) */ server_closed(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/server_description.hpp b/src/mongocxx/include/mongocxx/v1/events/server_description.hpp index 389427057e..818c74d764 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_description.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_description.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +41,91 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_description {}; +class server_description { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~server_description(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() server_description(server_description&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(server_description&) operator=(server_description&& other) noexcept; + + /// + /// Copy constructor. + /// + server_description(server_description const& other); + + /// + /// Copy assignment. + /// + server_description& operator=(server_description const& other); + + /// + /// Return the client-generated unique server ID. + /// + /// @note The server ID is unique only for the associated client or client pool. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint32_t) id() const; + + /// + /// Return the client-measured execution time of the "hello" command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) round_trip_time() const; + + /// + /// Return the topology type. + /// + /// @returns One of: + /// - "LoadBalancer" + /// - "Mongos" + /// - "PossiblePrimary" + /// - "RSArbiter" + /// - "RSGhost" + /// - "RSOther" + /// - "RSPrimary" + /// - "RSSecondary" + /// - "Standalone" + /// - "Unknown" + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) type() const; + + /// + /// Return the raw server response to the "hello" command. + /// + /// @returns Empty when connection was unsuccessful or a client-side error was encountered. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) hello() const; + + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp index 9421a55efe..46a9df8de7 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp @@ -20,6 +20,17 @@ #include +#include + +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +43,39 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_description_changed {}; +class server_description_changed { + private: + void const* _impl; // mongoc_apm_server_changed_t const* + + public: + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + /// + /// Return the client-generated unique topology ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::oid) topology_id() const; + + /// + /// Return the previous server description. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::events::server_description) previous_description() const; + + /// + /// Return the new server description. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::events::server_description) new_description() const; + + private: + /* explicit(false) */ server_description_changed(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp index ae27b4b430..7aaab55b96 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp @@ -20,6 +20,13 @@ #include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +39,39 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_heartbeat_failed {}; +class server_heartbeat_failed { + private: + void const* _impl; // mongoc_apm_server_heartbeat_failed_t const* + + public: + /// + /// Return the error message. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) message() const; + + /// + /// Return the execution time of the event. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) duration() const; + + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + /// + /// Return true when this heartbeat event is for an awaitable "hello" (instead of a "legacy" hello). + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) awaited() const; + + private: + /* explicit(false) */ server_heartbeat_failed(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp index b3193a114f..942670fd1d 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp @@ -20,6 +20,13 @@ #include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +39,29 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_heartbeat_started {}; +class server_heartbeat_started { + private: + void const* _impl; // mongoc_apm_server_heartbeat_started_t const* + + public: + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + /// + /// Return true when this heartbeat event is for an awaitable "hello" (instead of a "legacy" hello). + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) awaited() const; + + private: + /* explicit(false) */ server_heartbeat_started(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp index 4fc3aaf5dc..4c1ed08328 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +41,39 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_heartbeat_succeeded {}; +class server_heartbeat_succeeded { + private: + void const* _impl; // mongoc_apm_server_heartbeat_succeeded_t const* + + public: + /// + /// Return the command reply. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) reply() const; + + /// + /// Return the execution time of the event. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) duration() const; + + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + /// + /// Return true when this heartbeat event is for an awaitable "hello" (instead of a "legacy" hello). + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) awaited() const; + + private: + /* explicit(false) */ server_heartbeat_succeeded(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp b/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp index 7e5d4b2c63..cba6f9a8cd 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +41,29 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_opening {}; +class server_opening { + private: + void const* _impl; // mongoc_apm_server_opening_t const* + + public: + /// + /// Return the hostname for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) host() const; + + /// + /// Return the port number for the connection used by the command. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; + + /// + /// Return the client-generated unique topology ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::oid) topology_id() const; + + private: + /* explicit(false) */ server_opening(void const* impl); +}; } // namespace events } // namespace v1 @@ -40,7 +71,6 @@ class server_opening {}; #include -/// /// @file /// Provides @ref mongocxx::v1::events::server_opening. /// diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp index 7317f7f669..4ff7187abd 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp @@ -20,6 +20,14 @@ #include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +40,19 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class topology_closed {}; +class topology_closed { + private: + void const* _impl; // mongoc_apm_topology_closed_t const* + + public: + /// + /// Return the client-generated unique topology ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::oid) topology_id() const; + + private: + /* explicit(false) */ topology_closed(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp index 0d092d213b..a18f84a2e7 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp @@ -20,6 +20,16 @@ #include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +42,41 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class topology_description {}; +class topology_description { + private: + void const* _impl; // mongoc_topology_description_t const* + + public: + /// + /// Return the topology type. + /// + /// @returns One of: + /// - "ReplicaSetNoPrimary" + /// - "ReplicaSetWithPrimary" + /// - "Sharded" + /// - "Single" + /// - "Unknown" + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) type() const; + + /// + /// Return true when a readable server is available according to this topology description. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) has_readable_server(v1::read_preference const& rp) const; + + /// + /// Return true when a writable server is available according to this topology description. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) has_writable_server() const; + + /// + /// Return the server descriptions for all servers in this topology description. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::vector) servers() const; + + private: + /* explicit(false) */ topology_description(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp index b95a8974b0..88198a2399 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp @@ -20,6 +20,14 @@ #include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +40,29 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class topology_description_changed {}; +class topology_description_changed { + private: + void const* _impl; // mongoc_apm_topology_changed_t const* + + public: + /// + /// Return the client-generated unique topology ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::oid) topology_id() const; + + /// + /// Return the previous topology description. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::events::topology_description) previous_description() const; + + /// + /// Return the new topology description. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::events::topology_description) new_description() const; + + private: + /* explicit(false) */ topology_description_changed(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp index 6eb2fee32f..7704138db0 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp @@ -20,6 +20,14 @@ #include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +40,19 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class topology_opening {}; +class topology_opening { + private: + void const* _impl; // mongoc_apm_topology_opening_t const* + + public: + /// + /// Return the client-generated unique topology ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::oid) topology_id() const; + + private: + /* explicit(false) */ topology_opening(void const* impl); +}; } // namespace events } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp b/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp index cb2c8a27e7..47f44dbbab 100644 --- a/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp @@ -20,19 +20,170 @@ #include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for a "findOneAndDelete" operation. /// +/// Supported fields include: +/// - `collation` +/// - `comment` +/// - `hint` +/// - `let` +/// - `max_time` ("maxTimeMS") +/// - `projection` +/// - `sort` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Query Documents (MongoDB Manual)](https://www.mongodb.com/docs/manual/tutorial/query-documents/) /// - [Delete Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/delete-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class find_one_and_delete_options {}; +class find_one_and_delete_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~find_one_and_delete_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_delete_options(find_one_and_delete_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) operator=(find_one_and_delete_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_delete_options(find_one_and_delete_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) operator=(find_one_and_delete_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_delete_options(); + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) projection(bsoncxx::v1::document::value projection); + + /// + /// Return the current "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) projection() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) sort(bsoncxx::v1::document::value ordering); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) write_concern(v1::write_concern write_concern); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_delete_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp b/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp index 3d089d3424..d9ec449454 100644 --- a/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp @@ -20,19 +20,205 @@ #include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for a "findOneAndReplace" operation. /// +/// Supported fields include: +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `collation` +/// - `comment` +/// - `hint` +/// - `let` +/// - `max_time` ("maxTimeMS") +/// - `projection` +/// - `return_document` ("returnDocument") +/// - `sort` +/// - `upsert` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Query Documents (MongoDB Manual)](https://www.mongodb.com/docs/manual/tutorial/query-documents/) /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class find_one_and_replace_options {}; +class find_one_and_replace_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~find_one_and_replace_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_replace_options(find_one_and_replace_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) operator=(find_one_and_replace_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_replace_options(find_one_and_replace_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) operator=(find_one_and_replace_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_replace_options(); + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) bypass_document_validation( + bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; + + /// + /// Set the "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) projection(bsoncxx::v1::document::value projection); + + /// + /// Return the current "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) projection() const; + + /// + /// Set the "returnDocument" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) return_document(return_document return_document); + + /// + /// Return the current "returnDocument" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) return_document() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) sort(bsoncxx::v1::document::value ordering); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) upsert(bool upsert); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_replace_options&) write_concern(v1::write_concern write_concern); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp b/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp index f5bef75d2b..e885e1a99e 100644 --- a/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp @@ -20,19 +20,217 @@ #include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for a "findOneAndUpdate" operation. /// +/// Supported fields include: +/// - `array_filters ("arrayFilters")` +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `collation` +/// - `comment` +/// - `hint` +/// - `let` +/// - `max_time` ("maxTimeMS") +/// - `projection` +/// - `return_document` ("returnDocument") +/// - `sort` +/// - `upsert` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Query Documents (MongoDB Manual)](https://www.mongodb.com/docs/manual/tutorial/query-documents/) /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class find_one_and_update_options {}; +class find_one_and_update_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~find_one_and_update_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_update_options(find_one_and_update_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) operator=(find_one_and_update_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_update_options(find_one_and_update_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) operator=(find_one_and_update_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_one_and_update_options(); + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; + + /// + /// Set the "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) projection(bsoncxx::v1::document::value projection); + + /// + /// Return the current "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) projection() const; + + /// + /// Set the "returnDocument" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) return_document(return_document return_document); + + /// + /// Return the current "returnDocument" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) return_document() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) sort(bsoncxx::v1::document::value ordering); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) upsert(bool upsert); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) write_concern(v1::write_concern write_concern); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_one_and_update_options&) array_filters(bsoncxx::v1::array::value array_filters); + + /// + /// Return the current "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) array_filters() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/find_options.hpp b/src/mongocxx/include/mongocxx/v1/find_options.hpp index 4178ecea66..3e05539d25 100644 --- a/src/mongocxx/include/mongocxx/v1/find_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_options.hpp @@ -20,18 +20,303 @@ #include +#include +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// Options for a "find" command. /// +/// Supported fields include: +/// - `allow_disk_use` ("allowDiskUse") +/// - `allow_partial_results` ("allowPartialResults") +/// - `batch_size` ("batchSize") +/// - `collation` +/// - `comment` +/// - `cursor_type` ("cursorType") +/// - `hint` +/// - `let` +/// - `limit` +/// - `max_await_time` ("maxAwaitTimeMS") +/// - `max_time` ("maxTimeMS") +/// - `max` +/// - `min` +/// - `no_cursor_timeout` ("noCursorTimeout") +/// - `projection` +/// - `read_preference` ("readPreference") +/// - `return_key` ("returnKey") +/// - `show_record_id` ("showRecordId") +/// - `skip` +/// - `sort` +/// /// @see /// - [`find` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/find/) /// /// @attention This feature is experimental! It is not ready for use! /// -class find_options {}; +class find_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~find_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_options(find_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) operator=(find_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_options(find_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) operator=(find_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() find_options(); + + /// + /// Set the "allowDiskUse" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) allow_disk_use(bool allow_disk_use); + + /// + /// Return the current "allowDiskUse" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) allow_disk_use() const; + + /// + /// Set the "allowPartialResults" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) allow_partial_results(bool allow_partial); + + /// + /// Return the current "allowPartialResults" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) allow_partial_results() const; + + /// + /// Set the "batchSize" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) batch_size(std::int32_t batch_size); + + /// + /// Return the current "batchSize" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) batch_size() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) comment(std::string comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; + + /// + /// Set the "cursorType" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) cursor_type(v1::cursor::type cursor_type); + + /// + /// Return the current "cursorType" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) cursor_type() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "limit" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) limit(std::int64_t limit); + + /// + /// Return the current "limit" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) limit() const; + + /// + /// Set the "max" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) max(bsoncxx::v1::document::value max); + + /// + /// Return the current "max" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max() const; + + /// + /// Set the "maxAwaitTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) max_await_time(std::chrono::milliseconds max_await_time); + + /// + /// Return the current "maxAwaitTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_await_time() const; + + /// + /// Set the "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "min" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) min(bsoncxx::v1::document::value min); + + /// + /// Return the current "min" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) min() const; + + /// + /// Set the "noCursorTimeout" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) no_cursor_timeout(bool no_cursor_timeout); + + /// + /// Return the current "noCursorTimeout" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) no_cursor_timeout() const; + + /// + /// Set the "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) projection(bsoncxx::v1::document::value projection); + + /// + /// Return the current "projection" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) projection() const; + + /// + /// Set the "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) read_preference(v1::read_preference rp); + + /// + /// Return the current "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_preference() const; + + /// + /// Set the "returnKey" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) return_key(bool return_key); + + /// + /// Return the current "returnKey" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) return_key() const; + + /// + /// Set the "showRecordId" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) show_record_id(bool show_record_id); + + /// + /// Return the current "showRecordId" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) show_record_id() const; + + /// + /// Set the "skip" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) skip(std::int64_t skip); + + /// + /// Return the current "skip" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) skip() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(find_options&) sort(bsoncxx::v1::document::value ordering); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp index 4cb5c55141..8f607d24d9 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp @@ -20,6 +20,33 @@ #include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -32,7 +59,382 @@ namespace gridfs { /// /// @attention This feature is experimental! It is not ready for use! /// -class bucket {}; +class bucket { + private: + class impl; + std::unique_ptr _impl; + + public: + class options; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~bucket(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() bucket(bucket&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() bucket(bucket const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(bucket&) operator=(bucket const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() bucket(); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Equivalent to @ref open_upload_stream_with_id with a file ID generated using @ref bsoncxx::v1::oid. + /// + /// @{ + v1::gridfs::uploader open_upload_stream( + bsoncxx::v1::stdx::string_view filename, + v1::gridfs::upload_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::uploader) open_upload_stream( + v1::client_session const& session, + bsoncxx::v1::stdx::string_view filename, + v1::gridfs::upload_options const& opts = {}); + /// @} + /// + + /// + /// Return an uploader for a new file to this bucket. + /// + /// @note The file is not completely uploaded until @ref mongocxx::v1::gridfs::uploader::close() is invoked. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::invalid_chunk_size_bytes if the + /// "chunkSizeBytes" field is not a positive value. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::uploader) open_upload_stream_with_id( + bsoncxx::v1::types::view id, + bsoncxx::v1::stdx::string_view filename, + v1::gridfs::upload_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::uploader) open_upload_stream_with_id( + v1::client_session const& session, + bsoncxx::v1::types::view id, + bsoncxx::v1::stdx::string_view filename, + v1::gridfs::upload_options const& opts = {}); + /// @} + /// + + /// + /// Equivalent to @ref upload_from_stream_with_id with a file ID generated using @ref bsoncxx::v1::oid. + /// + /// @note The file is not completely uploaded until @ref mongocxx::v1::gridfs::uploader::close() is invoked. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::upload_result) upload_from_stream( + bsoncxx::v1::stdx::string_view filename, + std::istream& input, + v1::gridfs::upload_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::upload_result) upload_from_stream( + v1::client_session const& session, + bsoncxx::v1::stdx::string_view filename, + std::istream& input, + v1::gridfs::upload_options const& opts = {}); + /// @} + /// + + /// + /// Upload the contents of `input` as a new file to this bucket. + /// + /// @throws std::ios_base::failure if an error is encountered when reading from `input`. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(void) upload_from_stream_with_id( + bsoncxx::v1::types::view id, + bsoncxx::v1::stdx::string_view filename, + std::istream& input, + v1::gridfs::upload_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(void) upload_from_stream_with_id( + v1::client_session const& session, + bsoncxx::v1::types::view id, + bsoncxx::v1::stdx::string_view filename, + std::istream& input, + v1::gridfs::upload_options const& opts = {}); + /// @} + /// + + /// + /// Return a downloader for the requested file from this bucket. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::not_found if the requested file + /// does not exist. + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::corrupt_data if the + /// GridFS file data is invalid or inconsistent. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::downloader) open_download_stream(bsoncxx::v1::types::view id); + + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::downloader) open_download_stream( + v1::client_session const& session, + bsoncxx::v1::types::view id); + /// @} + /// + + /// + /// Download the entire contents of the requested file from this bucket into `output`. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::not_found if the requested file + /// does not exist. + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::corrupt_data if the + /// GridFS file data is invalid or inconsistent. + /// @throws std::ios_base::failure if an error is encountered when writing to `output`. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(void) download_to_stream(bsoncxx::v1::types::view id, std::ostream& output); + + MONGOCXX_ABI_EXPORT_CDECL(void) + download_to_stream(v1::client_session const& session, bsoncxx::v1::types::view id, std::ostream& destination); + /// @} + /// + + /// + /// Partially download the contents of the requested file from this bucket into `output`. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::not_found if the requested file + /// does not exist. + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::corrupt_data if the + /// GridFS file data is invalid or inconsistent. + /// @throws std::ios_base::failure if an error is encountered when writing to `output`. + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::invalid_byte_range if `[start, + /// end)` is not a valid range of byte indexes within the requested file. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(void) + download_to_stream(bsoncxx::v1::types::view id, std::ostream& output, std::size_t start, std::size_t end); + + MONGOCXX_ABI_EXPORT_CDECL(void) download_to_stream( + v1::client_session const& session, + bsoncxx::v1::types::view id, + std::ostream& output, + std::size_t start, + std::size_t end); + /// @} + /// + + /// + /// Delete the requested file from this bucket. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::bucket::errc::not_found if the requested file + /// does not exist. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(void) delete_file(bsoncxx::v1::types::view id); + + MONGOCXX_ABI_EXPORT_CDECL(void) delete_file(v1::client_session const& session, bsoncxx::v1::types::view id); + /// @} + /// + + /// + /// Find files within this bucket matching the given query filter. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) find(bsoncxx::v1::document::view filter, v1::find_options const& opts = {}); + + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) + find(v1::client_session const& session, bsoncxx::v1::document::view filter, v1::find_options const& opts = {}); + /// @} + /// + + /// + /// Return the name of this bucket. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) bucket_name() const; + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::gridfs::bucket. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + invalid_chunk_size_bytes, ///< The "chunkSizeBytes" field must be a positive value. + not_found, ///< The requested GridFS file does not exist. + corrupt_data, ///< The GridFS file is in an invalid or inconsistent state. + invalid_byte_range, ///< [start, end) must be a valid range of byte indexes within the requested GridFS file. + }; + + /// + /// The error category for @ref mongocxx::v1::gridfs::bucket::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } +}; + +/// +/// Options for @ref mongocxx::v1::gridfs::bucket. +/// +/// Supported fields include: +/// - `bucket_name` ("bucketName") +/// - `chunk_size_bytes` ("chunkSizeBytes") +/// - `read_concern` ("readConcern") +/// - `read_preference` ("readPreference") +/// - `write_concern` ("writeConcern") +/// +/// @see +/// - [GridFS (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/gridfs/gridfs-spec/) +/// - [GridFS for Self-Managed Deployments (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/gridfs/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bucket::options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Set the "bucketName" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) bucket_name(std::string v); + + /// + /// Return the current "bucketName" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bucket_name() const; + + /// + /// Set the "chunkSizeBytes" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) chunk_size_bytes(std::int32_t v); + + /// + /// Return the current "chunkSizeBytes" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) chunk_size_bytes() const; + + /// + /// Set the "readConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) read_concern(v1::read_concern v); + + /// + /// Return the current "readConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_concern() const; + + /// + /// Set the "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) read_preference(v1::read_preference v); + + /// + /// Return the current "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_preference() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) write_concern(v1::write_concern v); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; +}; } // namespace gridfs } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp index 8c468c9796..50e2b46579 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp @@ -20,6 +20,16 @@ #include +#include + +#include + +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -32,12 +42,138 @@ namespace gridfs { /// /// @attention This feature is experimental! It is not ready for use! /// -class downloader {}; +class downloader { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~downloader(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() downloader(downloader&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(downloader&) operator=(downloader&& other) noexcept; + + /// + /// This class is not copyable. + /// + downloader(downloader const& other) = delete; + + /// + /// This class is not copyable. + /// + downloader& operator=(downloader const& other) = delete; + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() downloader(); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state and `this->is_open() == true`. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Return true when the underlying GridFS file stream is open for reading. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) is_open() const; + + /// + /// Close the underlying GridFS download stream. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) close(); + + /// + /// Return the chunk size (in bytes) of the associated GridFS file. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int32_t) chunk_size() const; + + /// + /// Return the length of the associated GridFS file. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) file_length() const; + + /// + /// Return the files collection document for the associated GridFS file. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) files_document() const; + + /// + /// Read up to `length` bytes of the associated GridFS file. + /// + /// @par Preconditions: + /// - `data` is not null. + /// - The size of the storage region pointed to by `data` must be greater than or equal to `length`. + /// + /// @return The actual number of bytes read. `0` indicates the downloader has reached the end of the file. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::downloader::errc::is_closed if the + /// underlying GridFS download stream was already closed. + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::downloader::errc::corrupt_data if the + /// GridFS file data is invalid or inconsistent. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::size_t) read(std::uint8_t* data, std::size_t length); + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::gridfs::downloader. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + is_closed, ///< The GridFS file download stream is not open. + corrupt_data, ///< The GridFS file is in an invalid or inconsistent state. + }; + + /// + /// The error category for @ref mongocxx::v1::gridfs::downloader::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } +}; } // namespace gridfs } // namespace v1 } // namespace mongocxx +namespace std { + +template <> +struct is_error_code_enum : true_type {}; + +} // namespace std + #include /// diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp index 25bd8e9fc9..b776c0a607 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp @@ -20,6 +20,16 @@ #include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -27,12 +37,82 @@ namespace gridfs { /// /// Options related to uploading a file to a GridFS bucket. /// +/// Supported fields include: +/// - `chunk_size_bytes` ("chunkSizeBytes") +/// - `metadata` ("metadata") +/// /// @see /// - [GridFS (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/gridfs/) /// /// @attention This feature is experimental! It is not ready for use! /// -class upload_options {}; +class upload_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~upload_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() upload_options(upload_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(upload_options&) operator=(upload_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() upload_options(upload_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(upload_options&) operator=(upload_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() upload_options(); + + /// + /// Set the "chunkSizeBytes" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(upload_options&) chunk_size_bytes(std::int32_t chunk_size_bytes); + + /// + /// Return the current "chunkSizeBytes" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) chunk_size_bytes() const; + + /// + /// Set the "metadata" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(upload_options&) metadata(bsoncxx::v1::document::value metadata); + + /// + /// Return the current "metadata" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) metadata() const; +}; } // namespace gridfs } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp index a62b35ba2b..e22d2826dd 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp @@ -20,6 +20,12 @@ #include +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -27,12 +33,70 @@ namespace gridfs { /// /// Result of uploading a file to a GridFS bucket. /// +/// Supported fields include: +/// - `id` +/// /// @see /// - [GridFS (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/gridfs/) /// /// @attention This feature is experimental! It is not ready for use! /// -class upload_result {}; +class upload_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~upload_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() upload_result(upload_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(upload_result&) operator=(upload_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() upload_result(upload_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(upload_result&) operator=(upload_result const& other); + + /// + /// Return the ID of the uploaded GridFS file. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::view) id() const; + + /// + /// Compare equal when all supported fields compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(upload_result const& lhs, upload_result const& rhs); + + friend bool operator!=(upload_result const& lhs, upload_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace gridfs } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp index 34574053b4..f06731db98 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp @@ -20,6 +20,16 @@ #include +#include + +#include + +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -32,12 +42,174 @@ namespace gridfs { /// /// @attention This feature is experimental! It is not ready for use! /// -class uploader {}; +class uploader { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// Calls @ref close(). Any exceptions are caught and ignored. + /// + /// @note When a server-side error is encountered, already-uploaded chunks are "orphaned" and no cleanup attempt is + /// made. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~uploader(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() uploader(uploader&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(uploader&) operator=(uploader&& other) noexcept; + + /// + /// This class is not copyable. + /// + uploader(uploader const& other) = delete; + + /// + /// This class is not copyable. + /// + uploader& operator=(uploader const& other) = delete; + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() uploader(); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state and `this->is_open() == true`. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Return true when the underlying GridFS file stream is open for writing. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) is_open() const; + + /// + /// Complete the upload of this GridFS file. + /// + /// @note When a server-side error is encountered, already-uploaded chunks are "orphaned" and no cleanup attempt is + /// made. + /// + /// @returns The files collection document for the successfully uploaded GridFS file. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::upload_result) close(); + + /// + /// Abort uploading this GridFS file. + /// + /// @note When a server-side error is encountered, already-uploaded chunks are "orphaned" and no cleanup attempt is + /// made. + /// + /// @par Postconditions: + /// - All uploaded chunks for this GridFS file are deleted, unless a server-side error is encountered. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::uploader::errc::is_closed if the + /// underlying GridFS download stream was already closed. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) abort(); + + /// + /// Return the chunk size (in bytes) of the associated GridFS file. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int32_t) chunk_size() const; + + /// + /// Write `length` bytes of the associated GridFS file. + /// + /// An internal buffer is used to reduce the total number of collection write operations. Use @ref flush() to + /// manually flush the internal buffer. + /// + /// @note When a server-side error is encountered, already-uploaded chunks are "orphaned" and no cleanup attempt is + /// made. + /// + /// @par Preconditions: + /// - `data` is not null. + /// - The size of the storage region pointed to by `data` must be greater than or equal to `length`. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::uploader::errc::is_closed if the + /// underlying GridFS download stream was already closed. + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::uploader::errc::too_many_chunks if the + /// total number of chunks would be greater than or equal to INT32_MAX. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) write(std::uint8_t const* data, std::size_t length); + + /// + /// Flush the internal buffer. + /// + /// @note When a server-side error is encountered, already-uploaded chunks are "orphaned" and no cleanup attempt is + /// made. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::gridfs::uploader::errc::is_closed if the + /// underlying GridFS download stream was already closed. + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) flush(); + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::gridfs::uploader. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + is_closed, ///< The GridFS file upload stream is not open. + too_many_chunks, ///< The total number of chunks must be less than INT32_MAX. + }; + + /// + /// The error category for @ref mongocxx::v1::gridfs::uploader::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } +}; } // namespace gridfs } // namespace v1 } // namespace mongocxx +namespace std { + +template <> +struct is_error_code_enum : true_type {}; + +} // namespace std + #include /// diff --git a/src/mongocxx/include/mongocxx/v1/hint.hpp b/src/mongocxx/include/mongocxx/v1/hint.hpp index 6aafa91205..c2ae6490e8 100644 --- a/src/mongocxx/include/mongocxx/v1/hint.hpp +++ b/src/mongocxx/include/mongocxx/v1/hint.hpp @@ -20,6 +20,18 @@ #include +#include +#include + +#include +#include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -29,11 +41,150 @@ namespace v1 { /// A document or string that specifies the index to use to support the query predicate. /// /// @see -/// - [Query Plans (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/query-plans/#std-label-read-operations-query-optimization) +/// - [Query Optimization (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/query-optimization/) /// /// @attention This feature is experimental! It is not ready for use! /// -class hint {}; +class hint { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~hint(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() hint(hint&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(hint&) operator=(hint&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() hint(hint const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(hint&) operator=(hint const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `this->str().has_value() == false` + /// - `this->doc().has_value() == false` + /// + MONGOCXX_ABI_EXPORT_CDECL() hint(); + + /// + /// Initialize this "hint" option as a document. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() hint(std::string str); + + /// + /// Return the current "hint" option as a document. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() hint(bsoncxx::v1::document::value doc); + + /// + /// Return the current "hint" value as a string. + /// + /// @returns Empty when not a string. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) str() const; + + /// + /// Return the current "hint" value as a document. + /// + /// @returns Empty when not a document. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) doc() const; + + /// + /// Return the current "hint" value as a BSON type value. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::view) to_value() const; + + /// + /// Equivalent to to_value() const. + /// + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() operator bsoncxx::v1::types::view() const; + + /// + /// Compare equal when the underlying "hint" values compare equal. + /// + /// @{ + friend bool operator==(hint const& lhs, hint const& rhs) { + return lhs.str() == rhs.str() || lhs.doc() == rhs.doc(); + } + + friend bool operator!=(hint const& lhs, hint const& rhs) { + return !(lhs == rhs); + } + /// @} + /// + + /// + /// Equivalent to comparing `h.str()` with `str`. + /// + /// @{ + friend bool operator==(hint const& h, bsoncxx::v1::stdx::string_view str) { + return h.str() == str; + } + + friend bool operator!=(hint const& h, bsoncxx::v1::stdx::string_view str) { + return h.str() != str; + } + + friend bool operator==(bsoncxx::v1::stdx::string_view str, hint const& h) { + return str == h.str(); + } + + friend bool operator!=(bsoncxx::v1::stdx::string_view str, hint const& h) { + return str != h.str(); + } + /// @} + /// + + /// + /// Equivalent to comparing `h.doc()` and `doc`. + /// + /// @{ + friend bool operator==(hint const& h, bsoncxx::v1::document::view doc) { + return h.doc() == doc; + } + + friend bool operator!=(hint const& h, bsoncxx::v1::document::view doc) { + return h.doc() != doc; + } + + friend bool operator==(bsoncxx::v1::document::view doc, hint const& h) { + return doc == h.doc(); + } + + friend bool operator!=(bsoncxx::v1::document::view doc, hint const& h) { + return doc != h.doc(); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/indexes.hpp b/src/mongocxx/include/mongocxx/v1/indexes.hpp index 5a82652dac..9dc02eb69b 100644 --- a/src/mongocxx/include/mongocxx/v1/indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/indexes.hpp @@ -20,6 +20,26 @@ #include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -37,10 +57,18 @@ class indexes { // This class implements `IndexView` ("Index View API"): // - https://specifications.readthedocs.io/en/latest/index-management/index-management/ + private: + class impl; + std::unique_ptr _impl; + public: /// /// A description of a MongoDB index. /// + /// Supported fields include: + /// - `keys` + /// - `options` + /// /// @see /// - [Indexes (MongoDB Manual)](https://www.mongodb.com/docs/manual/indexes/) /// @@ -49,22 +77,642 @@ class indexes { class model { // This class implements `IndexModel` ("Index View API"): // - https://specifications.readthedocs.io/en/latest/index-management/index-management/ + + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~model(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() model(model&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model&& other) noexcept; + + /// + /// Copy constructor. + /// + MONGOCXX_ABI_EXPORT_CDECL() model(model const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model const& other); + + /// + /// Initialize with the given "keys" and "options" documents. + /// + MONGOCXX_ABI_EXPORT_CDECL() model(bsoncxx::v1::document::value keys, bsoncxx::v1::document::value options); + + /// + /// Initialize with the given "keys" document. + /// + /// @par Postconditions: + /// `this->options().empty() == true`. + /// + MONGOCXX_ABI_EXPORT_CDECL() model(bsoncxx::v1::document::value keys); + + /// + /// Return the current "keys" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) keys() const; + + /// + /// Return the current "options" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) options() const; }; /// /// Options for @ref mongocxx::v1::indexes. /// + /// Supported fields include: + /// - `background` + /// - `collation` + /// - `commit_quorum` ("commitQuorum") + /// - `default_language` + /// - `expire_after` ("expireAfterSeconds") + /// - `hidden` + /// - `language_override` + /// - `max_time` ("maxTimeMS") + /// - `name` + /// - `partial_filter_expression` ("partialFilterExpression") + /// - `sparse` + /// - `storage_engine` ("storageEngine") + /// - `twod_bits_precision` ("bits") + /// - `twod_location_max` ("max") + /// - `twod_location_min` ("min") + /// - `twod_sphere_version` ("2dsphereIndexVersion") + /// - `unique` + /// - `weights` + /// - `write_concern` ("writeConcern") + /// /// @attention This feature is experimental! It is not ready for use! /// class options { // This class implements `IndexOptions` ("Index View API"): // - https://specifications.readthedocs.io/en/latest/index-management/index-management/ + + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Set the "maxTime" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) max_time(std::chrono::milliseconds max_time); + + /// + /// Return the current "maxTime" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) write_concern(v1::write_concern write_concern); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "commitQuorum" field. + /// + /// @note Only applicable to "createIndexes" commands. Ignored by other commands. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) commit_quorum(std::int32_t commit_quorum); + + /// + /// Set the "commitQuorum" field. + /// + /// @note Only applicable to "createIndexes" commands. Ignored by other commands. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) commit_quorum(bsoncxx::v1::stdx::string_view commit_quorum); + + /// + /// Return the current "commitQuorum" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) commit_quorum() const; + + /// + /// Set the "background" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) background(bool background); + + /// + /// Return the current "background" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) background() const; + + /// + /// Set the "unique" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) unique(bool unique); + + /// + /// Return the current "unique" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) unique() const; + + /// + /// Set the "hidden" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) hidden(bool hidden); + + /// + /// Return the current "hidden" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hidden() const; + + /// + /// Set the "name" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) name(std::string name); + + /// + /// Return the current "name" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) name() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) collation(bsoncxx::v1::document::view collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "sparse" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) sparse(bool sparse); + + /// + /// Return the current "sparse" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sparse() const; + + /// + /// Set the "storageEngine" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) storage_engine( + bsoncxx::v1::stdx::optional storage_engine); + + /// + /// Return the current "storageEngine" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) storage_engine() const; + + /// + /// Set the "expireAfterSeconds" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) expire_after(std::chrono::seconds seconds); + + /// + /// Return the current "expireAfterSeconds" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) expire_after() const; + + /// + /// Set the "version" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) version(std::int32_t v); + + /// + /// Return the current "version" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) version() const; + + /// + /// Set the "weights" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) weights(bsoncxx::v1::document::view weights); + + /// + /// Return the current "weights" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) weights() const; + + /// + /// Set the "default_language" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) default_language(std::string default_language); + + /// + /// Return the current "default_language" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) default_language() const; + + /// + /// Set the "language_override" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) language_override(std::string language_override); + + /// + /// Return the current "language_override" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) language_override() + const; + + /// + /// Set the "partialFilterExpression" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) partial_filter_expression( + bsoncxx::v1::document::value partial_filter_expression); + + /// + /// Return the current "partialFilterExpression" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) partial_filter_expression() + const; + + /// + /// Set the "2dsphereIndexVersion" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) twod_sphere_version(std::uint8_t twod_sphere_version); + + /// + /// Return the current "2dsphereIndexVersion" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) twod_sphere_version() const; + + /// + /// Set the "bits" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) twod_bits_precision(std::uint8_t twod_bits_precision); + + /// + /// Return the current "bits" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) twod_bits_precision() const; + + /// + /// Set the "min" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) twod_location_min(double twod_location_min); + + /// + /// Return the current "min" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) twod_location_min() const; + + /// + /// Set the "max" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) twod_location_max(double twod_location_max); + + /// + /// Return the current "max" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) twod_location_max() const; + + /// + /// Return these index management options as a document. + /// + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() operator bsoncxx::v1::document::value() const; + }; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~indexes(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() indexes(indexes&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(indexes&) operator=(indexes&& other) noexcept; + + /// + /// Copy constructor. + /// + indexes(indexes const& other); + + /// + /// Copy assignment. + /// + options& operator=(indexes const& other); + + /// + /// Return all indexes in the associated collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list(); + + /// + /// Return all indexes in the associated collection. + /// + /// @param session The session with which this operation is associated. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list(v1::client_session const& session); + + /// + /// Equivalent to `this->create_one(...)` with a single index model. + /// + /// @param keys The "keys" field of the new index definition. + /// @param create_opts "createIndexes" command options. + /// @param opts Common index management options. + /// + bsoncxx::v1::stdx::optional create_one( + bsoncxx::v1::document::value keys, + bsoncxx::v1::document::value create_opts = {}, + options const& opts = {}) { + return this->create_one(model{std::move(keys), std::move(create_opts)}, opts); + } + + /// + /// Equivalent to `this->create_one(...)` with a single index model. + /// + /// @param session The session with which this operation is associated. + /// @param keys The "keys" field of the new index definition. + /// @param create_opts "createIndexes" command options. + /// @param opts Common index management options. + /// + bsoncxx::v1::stdx::optional create_one( + v1::client_session const& session, + bsoncxx::v1::document::value keys, + bsoncxx::v1::document::value create_opts = {}, + options const& opts = {}) { + return this->create_one(session, model{std::move(keys), std::move(create_opts)}, opts); + } + + /// + /// Create a single index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single index model. + /// + /// @param index The definition of the new index. The options must be applicable to the "createIndexes" command. + /// @param opts Common index management options. + /// + /// @returns The name of the created index. Empty when the index already exists. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) create_one( + model const& index, + options const& opts = {}); + + /// + /// Create a single index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single index model. + /// + /// @param session The session with which this operation is associated. + /// @param index The definition of the new index. The options must be applicable to the "createIndexes" command. + /// @param opts Common index management options. + /// + /// @returns The name of the created index. Empty when the index already exists. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + create_one(v1::client_session const& session, model const& index, options const& opts = {}); + + /// + /// Create multiple indexes in the associated collection. + /// + /// @param indexes The definitions of the new indexes. The options must be applicable to the "createIndexes" + /// command. + /// @param opts Common index management options. + /// + /// @returns The raw server response. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) create_many( + std::vector const& indexes, + options const& opts = {}); + + /// + /// Create multiple indexes in the associated collection. + /// + /// @param session The session with which this operation is associated. + /// @param indexes The definitions of the new indexes. The options must be applicable to the "createIndexes" + /// command. + /// @param opts Common index management options. + /// + /// @returns The raw server response. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) + create_many(v1::client_session const& session, std::vector const& indexes, options const& opts = {}); + + /// + /// Equivalent to `this->drop_one(mongocxx::v1::indexes::model(keys, drop_opts), ...)`. + /// + /// @param keys The "keys" field of the new index definition. + /// @param drop_opts "dropIndexes" command options. + /// @param opts Common index management options. + /// + void + drop_one(bsoncxx::v1::document::value keys, bsoncxx::v1::document::value drop_opts = {}, options const& opts = {}) { + return this->drop_one(model{std::move(keys), std::move(drop_opts)}, opts); + } + + /// + /// Equivalent to `this->drop_one(session, mongocxx::v1::indexes::model(keys, drop_opts), ...)`. + /// + /// @param session The session with which this operation is associated. + /// @param keys The "keys" field of the new index definition. + /// @param drop_opts "dropIndexes" command options. + /// @param opts Common index management options. + /// + void drop_one( + client_session const& session, + bsoncxx::v1::document::value keys, + bsoncxx::v1::document::value drop_opts = {}, + options const& opts = {}) { + return this->drop_one(session, model{std::move(keys), std::move(drop_opts)}, opts); + } + + /// + /// Drop a single index in the associated collection. + /// + /// @param index The name of index to drop. The options must be applicable to the "dropIndexes" command. + /// @param opts Common index management options. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::indexes::errc::invalid_name if `name` is equal to "*". + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) drop_one(bsoncxx::v1::stdx::string_view index, options const& opts = {}); + + /// + /// Drop a single index in the associated collection. + /// + /// @param session The session with which this operation is associated. + /// @param index The name of index to drop. The options must be applicable to the "dropIndexes" command. + /// @param opts Common index management options. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::indexes::errc::invalid_name if `name` is equal to "*". + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) + drop_one(v1::client_session const& session, bsoncxx::v1::stdx::string_view index, options const& opts = {}); + + /// + /// Drop a single index in the associated collection. + /// + /// @param index The description of the index to drop. The options must be applicable to the "dropIndexes" command. + /// @param opts Common index management options. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::indexes::errc::invalid_name if `name` is equal to "*". + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) drop_one(model const& index, options const& opts = {}); + + /// + /// Drop a single index in the associated collection. + /// + /// @param session The session with which this operation is associated. + /// @param index The description of the index to drop. + /// @param opts Common index management options. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) + drop_one(v1::client_session const& session, model const& index, options const& opts = {}); + + /// + /// Drop all indexes in the associated collection. + /// + /// @param opts Common index management options. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) drop_all(options const& opts = {}); + + /// + /// Drop all indexes in the associated collection. + /// + /// @param session The session with which this operation is associated. + /// @param opts Common index management options. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + MONGOCXX_ABI_EXPORT_CDECL(void) drop_all(v1::client_session const& session, options const& opts = {}); + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::indexes. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + invalid_name, ///< "*" is not a permitted index name. }; + + /// + /// The error category for @ref mongocxx::v1::instance::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } }; } // namespace v1 } // namespace mongocxx +namespace std { + +template <> +struct is_error_code_enum : true_type {}; + +} // namespace std + #include /// diff --git a/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp b/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp index ba97e03dac..6694fa58ae 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp @@ -20,18 +20,121 @@ #include +#include +#include + +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for an "insertMany" operation. /// +/// Supported fields include: +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `comment` +/// - `ordered` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Insert Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/insert-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class insert_many_options {}; +class insert_many_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~insert_many_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_many_options(insert_many_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_options&) operator=(insert_many_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_many_options(insert_many_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_options&) operator=(insert_many_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_many_options(); + + /// + /// Set the "bypass_document_validation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypass_document_validation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "write_concern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_options&) write_concern(v1::write_concern wc); + + /// + /// Return the current "write_concern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "ordered" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_options&) ordered(bool ordered); + + /// + /// Return the current "ordered" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) ordered() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp b/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp index bebb6ad5ec..a54a8fd75d 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp @@ -20,6 +20,14 @@ #include +#include + +#include +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +39,77 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class insert_many_result {}; +class insert_many_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~insert_many_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_many_result(insert_many_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_result&) operator=(insert_many_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_many_result(insert_many_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_many_result&) operator=(insert_many_result const& other); + + /// + /// Return the raw bulk write result. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; + + /// a + /// Return the number of inserted documents. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) inserted_count() const; + + /// + /// A map from the operation index to the inserted document ID. + /// + using id_map = std::map; + + /// + /// Return a map from the operation index to the inserted document ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(id_map) inserted_ids() const; + + /// + /// Compare equal when `lhs.result()` and `rhs.result()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(insert_many_result const& lhs, insert_many_result const& rhs); + + friend bool operator!=(insert_many_result const& lhs, insert_many_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp b/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp index 64982fe0ca..8b13dd5eb7 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp @@ -20,18 +20,110 @@ #include +#include +#include + +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for an "insertOne" operation. /// +/// Supported fields include: +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `comment` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Insert Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/insert-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class insert_one_options {}; +class insert_one_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~insert_one_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_one_options(insert_one_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_one_options&) operator=(insert_one_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_one_options(insert_one_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_one_options&) operator=(insert_one_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_one_options(); + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_one_options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_one_options&) write_concern(v1::write_concern wc); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_one_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) comment() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp b/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp index 4c00ce09b4..4bfbb24cfa 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp @@ -20,6 +20,13 @@ #include +#include + +#include +#include + +#include + namespace mongocxx { namespace v1 { @@ -31,7 +38,67 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class insert_one_result {}; +class insert_one_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~insert_one_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_one_result(insert_one_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_one_result&) operator=(insert_one_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() insert_one_result(insert_one_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(insert_one_result&) operator=(insert_one_result const& other); + + /// + /// Return the raw bulk write result. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; + + /// + /// Return the inserted document ID. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::types::view) inserted_id() const; + + /// + /// Compare equal when `lhs.result()` and `rhs.result()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(insert_one_result const& lhs, insert_one_result const& rhs); + + friend bool operator!=(insert_one_result const& lhs, insert_one_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/pipeline.hpp b/src/mongocxx/include/mongocxx/v1/pipeline.hpp index 1169b5d608..24e7f48c32 100644 --- a/src/mongocxx/include/mongocxx/v1/pipeline.hpp +++ b/src/mongocxx/include/mongocxx/v1/pipeline.hpp @@ -20,6 +20,16 @@ #include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +41,219 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class pipeline {}; +class pipeline { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~pipeline(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() pipeline(pipeline&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) operator=(pipeline&& other) noexcept; + + /// + /// Copy constructor. + /// + MONGOCXX_ABI_EXPORT_CDECL() pipeline(pipeline const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) operator=(pipeline const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `this->view().empty() == true` + /// + MONGOCXX_ABI_EXPORT_CDECL() pipeline(); + + /// + /// Return the current array of aggregation stages. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::array::view) view_array() const; + + /// + /// Append the given aggregation stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) append_stage(bsoncxx::v1::document::view v); + + /// + /// Append an array of aggregation stages. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) append_stages(bsoncxx::v1::array::view v); + + /// + /// Append the "$addFields" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) add_fields(bsoncxx::v1::document::view v); + + /// + /// Append the "$bucket" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) bucket(bsoncxx::v1::document::view v); + + /// + /// Append the "$bucketAuto" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) bucket_auto(bsoncxx::v1::document::view v); + + /// + /// Append the "$collStats" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) coll_stats(bsoncxx::v1::document::view v); + + /// + /// Append the "$collStats" stage with an empty document. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) coll_stats(); + + /// + /// Append the "$count" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) count(bsoncxx::v1::stdx::string_view v); + + /// + /// Append the "$currentOp" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) current_op(bsoncxx::v1::document::view v); + + /// + /// Append the "$facet" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) facet(bsoncxx::v1::document::view v); + + /// + /// Append the "$geoNear" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) geo_near(bsoncxx::v1::document::view v); + + /// + /// Append the "$graphLookup" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) graph_lookup(bsoncxx::v1::document::view v); + + /// + /// Append the "$group" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) group(bsoncxx::v1::document::view v); + + /// + /// Append the "$indexStats" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) index_stats(); + + /// + /// Append the "$limit" stage. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) limit(std::int32_t v); + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) limit(std::int64_t v); + /// @} + /// + + /// + /// Append the "$listLocalSessions" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) list_local_sessions(bsoncxx::v1::document::view v); + + /// + /// Append the "$listSessions" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) list_sessions(bsoncxx::v1::document::view v); + + /// + /// Append the "$lookup" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) lookup(bsoncxx::v1::document::view v); + + /// + /// Append the "$match" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) match(bsoncxx::v1::document::view v); + + /// + /// Append the "$merge" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) merge(bsoncxx::v1::document::view v); + + /// + /// Append the "$out" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) out(bsoncxx::v1::stdx::string_view v); + + /// + /// Append the "$project" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) project(bsoncxx::v1::document::view v); + + /// + /// Append the "$redact" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) redact(bsoncxx::v1::document::view v); + + /// + /// Append the "$replaceRoot" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) replace_root(bsoncxx::v1::document::view v); + + /// + /// Append the "$sample" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) sample(std::int32_t v); + + /// + /// Append the "$skip" stage. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) skip(std::int32_t v); + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) skip(std::int64_t v); + /// @} + /// + + /// + /// Append the "$sort" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) sort(bsoncxx::v1::document::view v); + + /// + /// Append the "$sortByCount" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) sort_by_count(bsoncxx::v1::document::view v); + + /// + /// Append the "$sortByCount" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) sort_by_count(bsoncxx::v1::stdx::string_view v); + + /// + /// Append the "$unwind" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) unwind(bsoncxx::v1::document::view v); + + /// + /// Append the "$unwind" stage. + /// + MONGOCXX_ABI_EXPORT_CDECL(pipeline&) unwind(bsoncxx::v1::stdx::string_view v); +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/pool.hpp b/src/mongocxx/include/mongocxx/v1/pool.hpp index 7962f8eabb..a99a9ab366 100644 --- a/src/mongocxx/include/mongocxx/v1/pool.hpp +++ b/src/mongocxx/include/mongocxx/v1/pool.hpp @@ -20,6 +20,19 @@ #include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -36,12 +49,254 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class pool { + private: + class impl; + std::unique_ptr _impl; + + public: + class options; + class entry; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all entries and clients associated with this pool. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~pool(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() pool(pool&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(pool&) operator=(pool&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() pool(pool const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(pool&) operator=(pool const& other); + + /// + /// Initialize this pool with the given URI. + /// + /// @note No connection is attempted until a client object is acquired from this pool. + /// + /// @throws mongocxx::v1::exception if a client-side error is encountered. + /// + /// @{ + explicit MONGOCXX_ABI_EXPORT_CDECL() pool(v1::uri const& uri, options const& opts); + + explicit MONGOCXX_ABI_EXPORT_CDECL() pool(v1::uri const& uri); + /// @} + /// + + /// + /// Initialize this pool with default URI options. + /// + /// @important No connection to the MongoDB server(s) is attempted until the first client object is acquired. /// - /// Options for @ref mongocxx::v1::pool. + /// @throws mongocxx::v1::exception if a client-side error is encountered. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() pool(); + + /// + /// Return a client object associated with this pool. + /// + /// This function blocks the current thread until a client object is available or "waitQueueTimeoutMS" is + /// triggered. + /// + /// @note The first client object acquired from the pool blocks the current thread until the initial connection to + /// the MongoDB server(s) is established. + /// + /// @returns A handle to a client object connected to the MongoDB server(s). + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::pool::errc::wait_queue_timeout if a client object could + /// not be acquired within "waitQueueTimeoutMS". + /// + MONGOCXX_ABI_EXPORT_CDECL(entry) acquire(); + + /// + /// Return a client object associated with this pool. + /// + /// @note The first client object acquired from a pool blocks the current thread until the initial connection to the + /// MongoDB server(s) is established. + /// + /// @returns Empty when a client object is not immediately available. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) try_acquire(); + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::collection. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + wait_queue_timeout, ///< Failed to acquire a client object due to "waitQueueTimeoutMS". + }; + + /// + /// The error category for @ref mongocxx::v1::collection::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. /// /// @attention This feature is experimental! It is not ready for use! /// - class options {}; + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } +}; + +/// +/// Options for @ref mongocxx::v1::pool. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class pool::options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other); + + /// + /// Initialize with client options to apply to a pool. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(v1::client::options opts); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `this->client_opts()` is default-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() options(); + + /// + /// Return the current client options. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::client::options) client_opts() const; +}; + +/// +/// A handle to a client object owned by an associated pool. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class pool::entry { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object, releasing the managed client object back to the associated pool. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~entry(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() entry(entry&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(entry&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() entry(entry const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(entry const& other); + + /// + /// Access the managed client. + /// + MONGOCXX_ABI_EXPORT_CDECL(client*) operator->(); + + /// + /// Access the managed client. + /// + MONGOCXX_ABI_EXPORT_CDECL(client&) operator*(); + + /// + /// Explicitly release the managed client object back to the associated pool. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(entry&) operator=(std::nullptr_t); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Equivalent to `(*this)->database(name)`. + /// + mongocxx::v1::database operator[](std::string name); }; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/range.hpp b/src/mongocxx/include/mongocxx/v1/range.hpp index 58bced2d7c..756464787b 100644 --- a/src/mongocxx/include/mongocxx/v1/range.hpp +++ b/src/mongocxx/include/mongocxx/v1/range.hpp @@ -20,18 +20,137 @@ #include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to range queries for Queryable Encryption. /// +/// Supported fields include: +/// - `max` +/// - `min` +/// - `precision` +/// - `sparsity` +/// - `trim_factor` ("trimFactor") +/// /// @see -/// - [Encrypted Fields and Enabled Queries](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/) +/// - [Client Side Encryption (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/client-side-encryption/client-side-encryption/) +/// - [Encrypted Fields and Enabled Queries (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/) /// /// @attention This feature is experimental! It is not ready for use! /// -class range {}; +class range { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~range(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() range(range&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(range&) operator=(range&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() range(range const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(range&) operator=(range const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() range(); + + /// + /// Set the "min" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(range&) min(bsoncxx::v1::types::value value); + + /// + /// Return the current "min" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + min() const; + + /// + /// Set the "max" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(range&) max(bsoncxx::v1::types::value value); + + /// + /// Return the current "max" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + max() const; + + /// + /// Set the "sparsity" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(range&) sparsity(std::int64_t value); + + /// + /// Return the current "sparsity" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + sparsity() const; + + /// + /// Set the "trimFactor" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(range&) trim_factor(std::int32_t value); + + /// + /// Return the current "trimFactor" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + trim_factor() const; + + /// + /// Set the "precision" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(range&) precision(std::int32_t value); + + /// + /// Return the current "precision" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + precision() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/read_concern.hpp b/src/mongocxx/include/mongocxx/v1/read_concern.hpp index 2cb5de4de3..efd8aedf84 100644 --- a/src/mongocxx/include/mongocxx/v1/read_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_concern.hpp @@ -20,18 +20,199 @@ #include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to a MongoDB Read Concern. /// +/// Supported fields include: +/// - `level` +/// /// @see /// - [Read Concern (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/read-concern/) +/// - [Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) /// /// @attention This feature is experimental! It is not ready for use! /// -class read_concern {}; +class read_concern { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// The read concern level. + /// + /// @see + /// - [Read Concern (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/read-concern/) + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class level { + /// + /// [Read Concern "local" (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/read-concern-local/) + /// + k_local, + + /// + /// [Read Concern "majority" (MongoDB + /// Manual)](https://www.mongodb.com/docs/manual/reference/read-concern-majority/) + /// + k_majority, + + /// + /// [Read Concern "linearizable" (MongoDB + /// Manual)](https://www.mongodb.com/docs/manual/reference/read-concern-linearizable/) + /// + k_linearizable, + + /// + /// [Default MongoDB Read Concerns/Write Concerns (MongoDB + /// Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + k_server_default, + + /// + /// An unknown (unsupported) read concern level. + /// + /// @note Not to be confused with @ref k_server_default. + /// + k_unknown, + + /// + /// [Read Concern "available" (MongoDB + /// Manual)](https://www.mongodb.com/docs/manual/reference/read-concern-available/) + /// + k_available, + + /// + /// [Read Concern "snapshot" (MongoDB + /// Manual)](https://www.mongodb.com/docs/manual/reference/read-concern-snapshot/) + /// + k_snapshot, + }; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~read_concern(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() read_concern(read_concern&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(read_concern&) operator=(read_concern&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() read_concern(read_concern const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(read_concern&) operator=(read_concern const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `this->level() == k_server_default` + /// + MONGOCXX_ABI_EXPORT_CDECL() read_concern(); + + /// + /// Set the read concern level. + /// + /// @param v One of: + /// - @ref k_local + /// - @ref k_majority + /// - @ref k_linearizable + /// - @ref k_server_default + /// - @ref k_available + /// - @ref k_snapshot + /// + MONGOCXX_ABI_EXPORT_CDECL(read_concern&) acknowledge_level(level v); + + /// + /// Return the current read concern level. + /// + MONGOCXX_ABI_EXPORT_CDECL(level) acknowledge_level() const; + + /// + /// Set the read concern level to an arbitrary string. + /// + /// @param v Equivalent to `this->acknowledge_level(k_server_default)` when `v.empty()`. + /// + /// @{ + read_concern& acknowledge_string(bsoncxx::v1::stdx::string_view v) { + this->acknowledge_string(v.empty() ? nullptr : std::string(v).c_str()); + return *this; + } + + read_concern& acknowledge_string(std::string const& v) { + this->acknowledge_string(v.empty() ? nullptr : v.c_str()); + return *this; + } + /// @} + /// + + /// + /// Set the read concern level to an arbitrary string. + /// + /// @param v Equivalent to `this->acknowledge_level(k_server_default)` when `v == nullptr`. + /// + MONGOCXX_ABI_EXPORT_CDECL(read_concern&) acknowledge_string(char const* v); + + /// + /// Return the current read concern level as a string. + /// + /// @returns Empty when `this->acknowledge_level()` is @ref k_server_default or @ref k_unknown. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) acknowledge_string() const; + + /// + /// Return this read concern option as a document. + /// + /// @par Preconditions: + /// - `this->acknowledge_level() != level::k_unknown`. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) to_document() const; + + /// + /// Compare equal when all supported fields compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(read_concern const& lhs, read_concern const& rhs); + + friend bool operator!=(read_concern const& lhs, read_concern const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/read_preference.hpp b/src/mongocxx/include/mongocxx/v1/read_preference.hpp index 89cfd4c190..ef0ef3a23b 100644 --- a/src/mongocxx/include/mongocxx/v1/read_preference.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_preference.hpp @@ -20,18 +20,175 @@ #include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to a MongoDB Read Preference. /// +/// Supported fields include: +/// - `max_staleness` ("maxStalenessSeconds") +/// - `mode` +/// - `tags` ("tag_sets") +/// /// @see /// - [Read Preference (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/read-preference/) /// /// @attention This feature is experimental! It is not ready for use! /// -class read_preference {}; +class read_preference { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// The read preference mode. + /// + /// @see + /// - [Read Preference (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/read-preference/) + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class read_mode { + /// + /// Primary member only (default). + /// + k_primary, + + /// + /// Primary member when available, secondary otherwise. + /// + k_primary_preferred, + + /// + /// Secondary members only. + /// + k_secondary, + + /// + /// Secondary members when available, primary otherwise. + /// + k_secondary_preferred, + + /// + /// A random eligible member based on a specified latency threshold. + /// + k_nearest, + }; + + /// + /// Destroy this object. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~read_preference(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() read_preference(read_preference&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(read_preference&) operator=(read_preference&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() read_preference(read_preference const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(read_preference&) operator=(read_preference const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `this->mode() == k_primary` + /// - `this->tags().empty() == true` + /// - `this->max_staleness().has_value() == false` + /// + MONGOCXX_ABI_EXPORT_CDECL() read_preference(); + + /// + /// Set the "mode" field. + /// + /// @param v One of: + /// - @ref k_primary + /// - @ref k_primary_preferred + /// - @ref k_secondary + /// - @ref k_secondary_preferred + /// - @ref k_nearest + /// Any unsupported value is interpreted as @ref k_primary. + /// + /// @see + /// - [Read Preference Use Cases](https://www.mongodb.com/docs/manual/core/read-preference-use-cases/) + /// + MONGOCXX_ABI_EXPORT_CDECL(read_preference&) mode(read_mode v); + + /// + /// Return the current "mode" field + /// + MONGOCXX_ABI_EXPORT_CDECL(read_mode) mode() const; + + /// + /// Set the "tag_sets" field. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(read_preference&) tags(bsoncxx::v1::array::view v); + MONGOCXX_ABI_EXPORT_CDECL(read_preference&) tags(bsoncxx::v1::document::view v); + /// @} + /// + + /// + /// Return the current "tag_sets" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::array::view) tags() const; + + /// + /// Set the "maxStalenessSeconds" field. + /// + /// @param v `-1` is equivalent to "unset". + /// + MONGOCXX_ABI_EXPORT_CDECL(read_preference&) max_staleness(std::chrono::seconds v); + + /// + /// Return the current "maxStalenessSeconds" field. + /// + /// @returns An empty optional if the option is unset. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_staleness() const; + + /// + /// Compare equal when all supported fields compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(read_preference const& lhs, read_preference const& rhs); + + friend bool operator!=(read_preference const& lhs, read_preference const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp b/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp index 9fae0560bd..ec3dd0b8ba 100644 --- a/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp @@ -20,18 +20,168 @@ #include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for a "replaceOne" operation. /// +/// Supported fields include: +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `collation` +/// - `comment` +/// - `hint` +/// - `let` +/// - `sort` +/// - `upsert` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class replace_one_options {}; +class replace_one_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~replace_one_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one_options(replace_one_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) operator=(replace_one_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one_options(replace_one_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) operator=(replace_one_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one_options(); + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) upsert(bool upsert); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) write_concern(v1::write_concern wc); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) sort(bsoncxx::v1::document::value sort); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp b/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp index 843e47ffb4..32012087bb 100644 --- a/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp @@ -20,6 +20,16 @@ #include +#include + +#include + +#include +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +41,79 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class replace_one_result {}; +class replace_one_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~replace_one_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one_result(replace_one_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_result&) operator=(replace_one_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() replace_one_result(replace_one_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(replace_one_result&) operator=(replace_one_result const& other); + + /// + /// Return the raw bulk write result. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; + + /// + /// Return the number of documents that matched the filter. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) matched_count() const; + + /// + /// Return the number of documents that were modified. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) modified_count() const; + + /// + /// Return the upserted document ID. + /// + /// @returns Empty when `this->modified_count() == 0`. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upserted_id() const; + + /// + /// Compare equal when `lhs.result()` and `rhs.result()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(replace_one_result const& lhs, replace_one_result const& rhs); + + friend bool operator!=(replace_one_result const& lhs, replace_one_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/return_document.hpp b/src/mongocxx/include/mongocxx/v1/return_document.hpp index 08ffec753b..0e62ccf64f 100644 --- a/src/mongocxx/include/mongocxx/v1/return_document.hpp +++ b/src/mongocxx/include/mongocxx/v1/return_document.hpp @@ -27,9 +27,23 @@ namespace v1 { /// `returnDocument` from the CRUD API specification. /// /// @see -/// - [CRUD API (MongoDB Specifications)](https://www.mongodb.com/docs/manual/reference/command/return_document/) +/// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) /// -enum class return_document {}; +enum class return_document { + /// + /// Return the original document. + /// + /// @note Equivalent to `"returnNewDocument": false`. + /// + k_before, + + /// + /// Return the updated document. + /// + /// @note Equivalent to `"returnNewDocument": true`. + /// + k_after, +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp index d67d3e30c6..5b8125689b 100644 --- a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp @@ -20,25 +20,104 @@ #include +#include +#include + +#include +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for a "rewrapManyDataKey" operation. /// +/// Supported fields include: +/// - `master_key` ("masterKey") +/// - `provider` +/// /// @see /// - [Rotate and Rewrap Encryption Keys (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-keys/) /// /// @attention This feature is experimental! It is not ready for use! /// -class rewrap_many_datakey_options {}; +class rewrap_many_datakey_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~rewrap_many_datakey_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() rewrap_many_datakey_options(rewrap_many_datakey_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(rewrap_many_datakey_options&) operator=(rewrap_many_datakey_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() rewrap_many_datakey_options(rewrap_many_datakey_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(rewrap_many_datakey_options&) operator=(rewrap_many_datakey_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() rewrap_many_datakey_options(); + + /// + /// Set the "provider" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(rewrap_many_datakey_options&) provider(std::string provider); + + /// + /// Return the current "provider" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) provider() const; + + /// + /// Set the "masterKey" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(rewrap_many_datakey_options&) master_key(bsoncxx::v1::document::value master_key); + + /// + /// Return the current "masterKey" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) master_key() const; +}; } // namespace v1 } // namespace mongocxx #include -/// /// @file /// Provides @ref mongocxx::v1::rewrap_many_datakey_options. /// diff --git a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp index cf94b863e1..e987dd00ff 100644 --- a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp @@ -20,18 +20,71 @@ #include +#include +#include + +#include + namespace mongocxx { namespace v1 { /// /// The result of a "rewrapManyDataKey" operation. /// +/// Supported fields include: +/// - `result` ("bulkWriteResult") +/// /// @see /// - [Rotate and Rewrap Encryption Keys (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-keys/) /// /// @attention This feature is experimental! It is not ready for use! /// -class rewrap_many_datakey_result {}; +class rewrap_many_datakey_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~rewrap_many_datakey_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() rewrap_many_datakey_result(rewrap_many_datakey_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(rewrap_many_datakey_result&) operator=(rewrap_many_datakey_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() rewrap_many_datakey_result(rewrap_many_datakey_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(rewrap_many_datakey_result&) operator=(rewrap_many_datakey_result const& other); + + /// + /// Return the current "bulkWriteResult" field. + /// + /// @returns Empty when the write operation is unacknowledged. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) result(); +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp index f6835c3108..76d943c196 100644 --- a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp @@ -20,6 +20,21 @@ #include +#include +#include + +#include +#include + +#include + +#include +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -34,15 +49,343 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class search_indexes { + private: + class impl; + std::unique_ptr _impl; + + public: + class model; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~search_indexes(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() search_indexes(search_indexes&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(search_indexes&) operator=(search_indexes&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() search_indexes(search_indexes const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(search_indexes&) operator=(search_indexes const& other); + + /// + /// Return information for all search indexes in the associated collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list(v1::aggregate_options const& opts = {}); + + /// + /// Return information for all search indexes in the associated collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list( + v1::client_session const& session, + v1::aggregate_options const& opts = {}); + + /// + /// Return information for the search index with the given name in the associated collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list( + bsoncxx::v1::stdx::string_view name, + v1::aggregate_options const& opts = {}); + + /// + /// Return information for the search index with the given name in the associated collection. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) + list( + v1::client_session const& session, + bsoncxx::v1::stdx::string_view name, + v1::aggregate_options const& opts = {}); + + /// + /// Create a single search index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single search index model. + /// + /// @returns The name of the new search index. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) create_one(bsoncxx::v1::document::view definition); + + /// + /// Create a single search index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single search index model. + /// + /// @returns The name of the new search index. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) create_one( + v1::client_session const& session, + bsoncxx::v1::document::view definition); + + /// + /// Create a single search index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single search index model. + /// + /// @returns The name of the new search index. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) create_one( + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view definition); + + /// + /// Create a single search index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single search index model. + /// + /// @returns The name of the new search index. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) + create_one( + v1::client_session const& session, + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view definition); + + /// + /// Create a single search index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single search index model. + /// + /// @returns The name of the new search index. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) create_one(model const& index); + + /// + /// Create a single search index in the associated collection. + /// + /// Equivalent to `this->create_many(...)` with a single search index model. + /// + /// @returns The name of the new search index. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) /// - /// A description of a MongoDB Atlas Search index. + MONGOCXX_ABI_EXPORT_CDECL(std::string) create_one(client_session const& session, model const& index); + + /// + /// Create multiple search indexes in the associated collection. + /// + /// @returns The names of the new search indexes + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::vector) create_many(std::vector const& indexes); + + /// + /// Create multiple search indexes in the associated collection. + /// + /// @returns The names of the new search indexes. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`createSearchIndexes` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/) + /// + MONGOCXX_ABI_EXPORT_CDECL(std::vector) create_many( + client_session const& session, + std::vector const& indexes); + + /// + /// Drop the search index with the given name in the associated collection. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`dropSearchIndex` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/dropSearchIndex/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) drop_one(bsoncxx::v1::stdx::string_view name); + + /// + /// Drop the search index with the given name in the associated collection. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. /// /// @see - /// - [Queries and Indexes (MongoDB Manual)](https://www.mongodb.com/docs/atlas/atlas-search/searching/) + /// - [`dropSearchIndex` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/dropSearchIndex/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) drop_one(v1::client_session const& session, bsoncxx::v1::stdx::string_view name); + + /// + /// Update the definition of the search index with the given name in the associated collection. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`updateSearchIndex` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/updateSearchIndex/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) update_one( + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view definition); + + /// + /// Update the definition of the search index with the given name in the associated collection. + /// + /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. + /// @throws mongocxx::v1::exception for all other runtime errors. + /// + /// @see + /// - [`updateSearchIndex` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/updateSearchIndex/) + /// + MONGOCXX_ABI_EXPORT_CDECL(void) + update_one( + client_session const& session, + bsoncxx::v1::stdx::string_view name, + bsoncxx::v1::document::view definition); +}; + +/// +/// A description of a MongoDB Atlas Search index. +/// +/// Supported fields include: +/// - `definition` +/// - `name` +/// - `type` +/// +/// @see +/// - [Queries and Indexes (MongoDB Manual)](https://www.mongodb.com/docs/atlas/atlas-search/searching/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class search_indexes::model { + // This class implements both `SearchIndexModel` and `SearchIndexOptions` ("Index View API"): + // - https://specifications.readthedocs.io/en/latest/index-management/index-management/ + + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~model(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() model(model&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() model(model const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model const& other); + + /// + /// Initialize this search index model with the given "name" and "definition". + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() + model(bsoncxx::v1::stdx::string_view name, bsoncxx::v1::document::value definition); + + /// + /// Initialize this search index model with the given "name". + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() + model(bsoncxx::v1::document::value definition); + + /// + /// Return the current "name" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) name() const; + + /// + /// Return the current "definition" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) definition() const; + + /// + /// Return the current "type" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) type() const; + /// - /// @attention This feature is experimental! It is not ready for use! + /// Set the "type" field. /// - class model {}; + MONGOCXX_ABI_EXPORT_CDECL(model&) type(bsoncxx::v1::stdx::string_view type); }; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/server_api.hpp b/src/mongocxx/include/mongocxx/v1/server_api.hpp index 91b19027fd..afe53ad15f 100644 --- a/src/mongocxx/include/mongocxx/v1/server_api.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_api.hpp @@ -20,23 +20,170 @@ #include +#include +#include + +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to MongoDB Stable API configuration. /// +/// Supported fields include: +/// - `version` +/// - `strict` +/// - `deprecation_errors` ("deprecationErrors") +/// /// @see /// - [Stable API (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/stable-api/) /// class server_api { // This class implements `ServerApi`: // - https://specifications.readthedocs.io/en/latest/versioned-api/versioned-api/ + + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// The server API version. + /// + /// @note Not to be confused with the MongoDB C++ Driver's API or ABI version. + /// + enum class version { + /// + /// Stable API Version 1. + /// + k_version_1, + }; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~server_api(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() server_api(server_api&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(server_api&) operator=(server_api&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() server_api(server_api const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(server_api&) operator=(server_api const& other); + + /// + /// Initialize with the given server API version. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() server_api(version v); + + /// + /// Return the given server API version as a string. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::server_api::errc::invalid_version when `v` is not a + /// valid server API version. + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::string) version_to_string(version v); + + /// + /// Return the given server API version as an enumerator. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::server_api::errc::invalid_version when `v` is not a + /// valid server API version. + /// + static MONGOCXX_ABI_EXPORT_CDECL(version) version_from_string(bsoncxx::v1::stdx::string_view v); + + /// + /// Set the "strict" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(server_api&) strict(bool strict); + + /// + /// Return the current "strict" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) strict() const; + + /// + /// Set the "deprecationErrors" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(server_api&) deprecation_errors(bool v); + + /// + /// Return the current "deprecationErrors" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) deprecation_errors() const; + + /// + /// Return the current "version" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(version) get_version() const; + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::server_api. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + invalid_version, ///< The server API version is invalid. + }; + + /// + /// The error category for @ref mongocxx::v1::server_api::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } }; } // namespace v1 } // namespace mongocxx +namespace std { + +template <> +struct is_error_code_enum : true_type {}; + +} // namespace std + #include /// diff --git a/src/mongocxx/include/mongocxx/v1/server_error-fwd.hpp b/src/mongocxx/include/mongocxx/v1/server_error-fwd.hpp index 23dc75320a..8d4dc55608 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error-fwd.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error-fwd.hpp @@ -23,7 +23,7 @@ namespace v1 { enum server_errc : int; -class server_error; +class MONGOCXX_ABI_EXPORT server_error; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index 7ca8863492..0364fb82f5 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -18,6 +18,16 @@ // +#include + +#include + +#include + +#include +#include + +#include #include #include @@ -27,19 +37,92 @@ namespace v1 { /// /// A MongoDB server error. /// -/// @important This class may contain both a client error code _and_ a server error code: -/// - Use `this->code()` to obtain the primary error code (which may equal `this->server_code()`). -/// - Use `this->server_code()` to obtain the server error code (which may equal `zero`). -/// Use @ref mongocxx::v1::source_errc to determine the origin of `this->code()`. +/// @important `this->code()` always returns the raw server error code. Use `this->client_code()` to query the +/// client-side error code. /// /// @par Inherits: /// - @ref mongocxx::v1::exception /// -class server_error {}; +class server_error : public v1::exception { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + ~server_error() override; + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_CDECL server_error(server_error&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + server_error& MONGOCXX_ABI_CDECL operator=(server_error&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_CDECL server_error(server_error const& other); + + /// + /// Copy assignment. + /// + server_error& MONGOCXX_ABI_CDECL operator=(server_error const& other); + + // Inherit constructors. + using v1::exception::exception; + + /// + /// The client error code. + /// + /// @returns Default-initialized when no client error code is available. + /// + std::error_code MONGOCXX_ABI_CDECL client_code() const; + + /// + /// The raw server error. + /// + /// @important The contents of the resulting BSON document may vary depending on the operation and error. + /// + bsoncxx::v1::document::view MONGOCXX_ABI_CDECL raw() const; + + /// + /// Return true if the raw server error contains the specified error label. + /// + /// @important The set of error labels may vary depending on the operation and error. + /// + /// @{ + bool MONGOCXX_ABI_CDECL has_error_label(char const* label) const; + + bool has_error_label(std::string const& label) const { + return this->has_error_label(label.c_str()); + } + + bool has_error_label(bsoncxx::v1::stdx::string_view label) const { + return this->has_error_label(std::string(label).c_str()); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx +#include + /// /// @file /// Provides @ref mongocxx::v1::server_error. diff --git a/src/mongocxx/include/mongocxx/v1/tls.hpp b/src/mongocxx/include/mongocxx/v1/tls.hpp index 1162f9a266..0197f983c9 100644 --- a/src/mongocxx/include/mongocxx/v1/tls.hpp +++ b/src/mongocxx/include/mongocxx/v1/tls.hpp @@ -20,16 +20,139 @@ #include +#include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to TLS configuration. /// +/// Supported fields include: +/// - `allow_invalid_certificates` ("weak_cert_validation") +/// - `ca_dir` +/// - `ca_file` +/// - `crl_file` +/// - `pem_file` +/// - `pem_password` ("pem_pwd") +/// /// @see +/// - [`mongoc_ssl_opt_t` (mongoc)](https://mongoc.org/libmongoc/current/mongoc_ssl_opt_t.html) /// - [TLS/SSL (Transport Encryption) (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/security-transport-encryption/) /// -class tls {}; +class tls { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~tls(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() tls(tls&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) operator=(tls&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() tls(tls const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) operator=(tls const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() tls(); + + /// + /// Set the "pem_file" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) pem_file(std::string v); + + /// + /// Return the current "pem_file" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) pem_file() const; + + /// + /// Set the "pem_pwd" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) pem_password(std::string v); + + /// + /// Return the current "pem_pwd" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) pem_password() const; + + /// + /// Set the "ca_file" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) ca_file(std::string v); + + /// + /// Retur the current "ca_file" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) ca_file() const; + + /// + /// Set the "ca_dir" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) ca_dir(std::string v); + + /// + /// Return the current "ca_dir" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) ca_dir() const; + + /// + /// Set the "crl_file" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) crl_file(std::string v); + + /// + /// Return the current "crl_file" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) crl_file() const; + + /// + /// Set the "weak_cert_validation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(tls&) allow_invalid_certificates(bool v); + + /// + /// Return the current "weak_cert_validation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) allow_invalid_certificates() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/transaction.hpp b/src/mongocxx/include/mongocxx/v1/transaction.hpp index 7bcb163159..9473c6212f 100644 --- a/src/mongocxx/include/mongocxx/v1/transaction.hpp +++ b/src/mongocxx/include/mongocxx/v1/transaction.hpp @@ -20,18 +20,121 @@ #include +#include +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to a distributed transaction. /// +/// Supported fields include: +/// - `max_commit_time_ms` ("maxCommitTimeMS") +/// - `read_concern` ("readConcern") +/// - `read_preference` ("readPreference") +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Transactions (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/transactions/) /// /// @attention This feature is experimental! It is not ready for use! /// -class transaction {}; +class transaction { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~transaction(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() transaction(transaction&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(transaction&) operator=(transaction&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() transaction(transaction const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(transaction&) operator=(transaction const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() transaction(); + + /// + /// Set the "maxCommitTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(transaction&) max_commit_time_ms(std::chrono::milliseconds v); + + /// + /// Return the current "maxCommitTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_commit_time_ms() const; + + /// + /// Set the "readConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(transaction&) read_concern(v1::read_concern const& v); + + /// + /// Return the current "readConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_concern() const; + + /// + /// Set the "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(transaction&) read_preference(v1::read_preference const& v); + + /// + /// Return the current "readPreference" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) read_preference() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(transaction&) write_concern(v1::write_concern const& v); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/update_many_options.hpp b/src/mongocxx/include/mongocxx/v1/update_many_options.hpp index 6d20a3ebbd..7f747386e1 100644 --- a/src/mongocxx/include/mongocxx/v1/update_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_many_options.hpp @@ -20,18 +20,181 @@ #include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for an "updateMany" operation. /// +/// Supported fields include: +/// - `array_filters` ("arrayFilters") +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `collation` +/// - `comment` +/// - `hint` +/// - `let` +/// - `sort` +/// - `upsert` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class update_many_options {}; +class update_many_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~update_many_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many_options(update_many_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) operator=(update_many_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many_options(update_many_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) operator=(update_many_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many_options(); + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) sort(bsoncxx::v1::document::value sort); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) upsert(bool upsert); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) write_concern(v1::write_concern wc); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_options&) array_filters(bsoncxx::v1::array::value array_filters); + + /// + /// Return the current "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) array_filters() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/update_many_result.hpp b/src/mongocxx/include/mongocxx/v1/update_many_result.hpp index d05c3959af..3de3130318 100644 --- a/src/mongocxx/include/mongocxx/v1/update_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_many_result.hpp @@ -20,6 +20,17 @@ #include +#include + +#include + +#include +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +42,89 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class update_many_result {}; +class update_many_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~update_many_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many_result(update_many_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_result&) operator=(update_many_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_many_result(update_many_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_many_result&) operator=(update_many_result const& other); + + /// + /// Return the raw bulk write result. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; + + /// + /// Return the number of documents that matched the filter. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) matched_count() const; + + /// + /// Return the number of documents that were modified. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) modified_count() const; + + /// + /// Return the number of documents that were upserted. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) upserted_count() const; + + /// + /// A map from the operation index to the upserted document ID. + /// + using id_map = std::map; + + /// + /// Return a map from the operation index to the upserted document ID. + /// + /// @returns Empty when the "upserted" field is not present or is empty. + /// + MONGOCXX_ABI_EXPORT_CDECL(id_map) upserted_ids() const; + + /// + /// Compare equal when `lhs.result()` and `rhs.result()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(update_many_result const& lhs, update_many_result const& rhs); + + friend bool operator!=(update_many_result const& lhs, update_many_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/update_one_options.hpp b/src/mongocxx/include/mongocxx/v1/update_one_options.hpp index ea4d4ab621..137d378afd 100644 --- a/src/mongocxx/include/mongocxx/v1/update_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_one_options.hpp @@ -20,18 +20,181 @@ #include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options for an "updateOne" operation. /// +/// Supported fields include: +/// - `array_filters` ("arrayFilters") +/// - `bypass_document_validation` ("bypassDocumentValidation") +/// - `collation` +/// - `comment` +/// - `hint` +/// - `let` +/// - `sort` +/// - `upsert` +/// - `write_concern` ("writeConcern") +/// /// @see /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) /// /// @attention This feature is experimental! It is not ready for use! /// -class update_one_options {}; +class update_one_options { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~update_one_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one_options(update_one_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) operator=(update_one_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one_options(update_one_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) operator=(update_one_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one_options(); + + /// + /// Set the "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) bypass_document_validation(bool bypass_document_validation); + + /// + /// Return the current "bypassDocumentValidation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) bypass_document_validation() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) collation(bsoncxx::v1::document::value collation); + + /// + /// Return the current "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) hint(v1::hint index_hint); + + /// + /// Return the current "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; + + /// + /// Set the "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) let(bsoncxx::v1::document::value let); + + /// + /// Return the current "let" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) let() const; + + /// + /// Set the "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) sort(bsoncxx::v1::document::value sort); + + /// + /// Return the current "sort" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) sort() const; + + /// + /// Set the "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) comment(bsoncxx::v1::types::value comment); + + /// + /// Return the current "comment" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional const) comment() const; + + /// + /// Set the "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) upsert(bool upsert); + + /// + /// Return the current "upsert" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upsert() const; + + /// + /// Set the "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) write_concern(v1::write_concern wc); + + /// + /// Return the current "writeConcern" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) write_concern() const; + + /// + /// Set the "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_options&) array_filters(bsoncxx::v1::array::value array_filters); + + /// + /// Return the current "arrayFilters" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) array_filters() const; +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/update_one_result.hpp b/src/mongocxx/include/mongocxx/v1/update_one_result.hpp index ebf3df6aa3..6f1b1bdb08 100644 --- a/src/mongocxx/include/mongocxx/v1/update_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_one_result.hpp @@ -20,6 +20,16 @@ #include +#include + +#include + +#include +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +41,84 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class update_one_result {}; +class update_one_result { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~update_one_result(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one_result(update_one_result&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_result&) operator=(update_one_result&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one_result(update_one_result const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(update_one_result&) operator=(update_one_result const& other); + + /// + /// Return the raw bulk write result. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; + + /// + /// Return the number of documents that matched the filter. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) matched_count() const; + + /// + /// Return the number of documents that were modified. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) modified_count() const; + + /// + /// Return the number of documents that were upserted. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) upserted_count() const; + + /// + /// Return the upserted document ID. + /// + /// @returns Empty when `this->upserted_count() == 0`. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upserted_id() const; + + /// + /// Compare equal when `lhs.result()` and `rhs.result()` compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(update_one_result const& lhs, update_one_result const& rhs); + + friend bool operator!=(update_one_result const& lhs, update_one_result const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/uri.hpp b/src/mongocxx/include/mongocxx/v1/uri.hpp index d23a8a4e80..81b8e238d3 100644 --- a/src/mongocxx/include/mongocxx/v1/uri.hpp +++ b/src/mongocxx/include/mongocxx/v1/uri.hpp @@ -1,4 +1,11 @@ -// Copyright 2009-present MongoDB, Inc. +/// +/// A MongoDB connection string. +/// +/// @see +/// - [Connection Strings (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/connection-string/) +/// +/// @attention This feature is experimental! It is not ready for use! +///// Copyright 2009-present MongoDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,18 +27,380 @@ #include +#include + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// A MongoDB connection string. /// +/// Supported fields include: +/// - `appname` ("appName") +/// - `auth_mechanism_properties` ("authMechanismProperties") +/// - `auth_mechanism` ("authMechanism") +/// - `auth_source` ("authSource") +/// - `compressors` +/// - `connect_timeout_ms` ("connectTimeoutMS") +/// - `database` +/// - `direct_connection` ("directConnection") +/// - `heartbeat_frequency_ms` ("heartbeatFrequencyMS") +/// - `hosts` +/// - `local_threshold_ms` ("localThresholdMS") +/// - `max_pool_size` ("maxPoolSize") +/// - `password` +/// - `read_concern` ("readConcern") +/// - `read_preference` ("readPreference") +/// - `replica_set` ("replicaSet") +/// - `retry_reads` ("retryReads") +/// - `retry_writes` ("retryWrites") +/// - `server_selection_timeout_ms` ("serverSelectionTimeoutMS") +/// - `server_selection_try_once` ("serverSelectionTryOnce") +/// - `socket_timeout_ms` ("socketTimeoutMS") +/// - `srv_max_hosts` ("srvMaxHosts") +/// - `tls_allow_invalid_certificates` ("tlsAllowInvalidCertificates") +/// - `tls_allow_invalid_hostnames` ("tlsAllowInvalidHostnames") +/// - `tls_ca_file` ("tlsCAFile") +/// - `tls_certificate_key_file_password` ("tlsCertificateKeyFilePassword") +/// - `tls_certificate_key_file` ("tlsCertificateKeyFile") +/// - `tls_disable_certificate_revocation_check` +/// - `tls_disable_ocsp_endpoint_check` +/// - `tls_insecure` ("tlsInsecure") +/// - `tls` +/// - `username` +/// - `wait_queue_timeout_ms` ("waitQueueTimeoutMS") +/// - `write_concern` ("writeConcern") +/// - `zlib_compression_level` ("zlibCompressionLevel") +/// /// @see /// - [Connection Strings (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/connection-string/) /// /// @attention This feature is experimental! It is not ready for use! /// -class uri {}; +class uri { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// A host identifier. + /// + struct host { + std::string name; ///< The host name. + std::uint16_t port; ///< The port number. + std::int32_t family; ///< The address family. + }; + + /// + /// The default connection string. + /// + static constexpr auto k_default_uri = "mongodb://localhost:27017"; + + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~uri(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() uri(uri&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(uri&) operator=(uri&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() uri(uri const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(uri&) operator=(uri const& other); + + /// + /// Equivalent to @ref uri(bsoncxx::v1::stdx::string_view v) with @ref k_default_uri. + /// + MONGOCXX_ABI_EXPORT_CDECL() uri(); + + /// + /// Initialize with the given connection string. + /// + /// @par Postconditions: + /// - All supported options specified by the connection string are set accordingly. + /// - `this->options()` returns a document containing all options specified by the connection string. + /// - All other supported options are "unset" or zero-initialized. + /// + /// @throws mongocxx::v1::exception if a client-side error is encountered. + /// + /// @{ + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() uri(char const* v); + + /* explicit(false) */ uri(bsoncxx::v1::stdx::string_view v) : uri{std::string{v}.c_str()} {} + + /* explicit(false) */ uri(std::string v) : uri{v.c_str()} {} + /// @} + /// + + /// + /// Return the "authMechanism" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) auth_mechanism() const; + + /// + /// Return the "authSource" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) auth_source() const; + + /// + /// Return the host(s) identifiers specified by the connection string. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::vector) hosts() const; + + /// + /// Return the database name specified by the connection string. + /// + /// @returns Empty when no database name was specified. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) database() const; + + /// + /// Return all URI options that were specified by the connection string. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) options() const; + + /// + /// Return the password specified by the connection string. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) password() const; + + /// + /// Return the "readConcern" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::read_concern) read_concern() const; + + /// + /// Return the "readPreference" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::read_preference) read_preference() const; + + /// + /// Return the "replicaSet" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) replica_set() const; + + /// + /// Return the "tls" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) tls() const; + + /// + /// Return this URI as a connection string. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) to_string() const; + + /// + /// Return the username specified by the connection string. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::string) username() const; + + /// + /// Return the "writeConcern" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(v1::write_concern) write_concern() const; + + /// + /// Return the "appName" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) appname() const; + + /// + /// Return the "authMechanismProperties" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) auth_mechanism_properties() + const; + + /// + /// Return the mongoc "credentials" field containing "authMechanism" and related options. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) credentials(); + + /// + /// Return the "srvMaxHosts" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) srv_max_hosts() const; + + /// + /// Return the "compressors" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::vector) compressors() const; + + /// + /// Return the "connectTimeoutMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) connect_timeout_ms() const; + + /// + /// Return the "directConnection" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) direct_connection() const; + + /// + /// Return the "heartbeatFrequencyMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) heartbeat_frequency_ms() const; + + /// + /// Return the "localThresholdMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) local_threshold_ms() const; + + /// + /// Return the "maxPoolSize" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_pool_size() const; + + /// + /// Return the "retryReads" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) retry_reads() const; + + /// + /// Return the "retryWrites" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) retry_writes() const; + + /// + /// Return the "serverSelectionTimeoutMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) server_selection_timeout_ms() const; + + /// + /// Return the "serverSelectionTryOnce" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) server_selection_try_once() const; + + /// + /// Set the "serverSelectionTryOnce" option. + /// + /// @throws mongocxx::v1::exception with @ref mongocxx::v1::uri::errc::set_failure if mongoc failed to set this URI + /// option. + /// + MONGOCXX_ABI_EXPORT_CDECL(uri&) server_selection_try_once(bool val); + + /// + /// Return the "socketTimeoutMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) socket_timeout_ms() const; + + /// + /// Return the "tlsAllowInvalidCertificates" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_allow_invalid_certificates() const; + + /// + /// Return the "tlsAllowInvalidHostnames" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_allow_invalid_hostnames() const; + + /// + /// Return the "tlsCAFile" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_ca_file() const; + + /// + /// Return the "tlsCertificateKeyFile" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_certificate_key_file() + const; + + /// + /// Return the "tlsCertificateKeyFilePassword" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) + tls_certificate_key_file_password() const; + + /// + /// Return the (mongoc-specific) "tlsDisableCertificateRevocationCheck" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_disable_certificate_revocation_check() const; + + /// + /// Return the (mongoc-specific) "tlsDisableOCSPEndpointCheck" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_disable_ocsp_endpoint_check() const; + + /// + /// Return the "tlsInsecure" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tls_insecure() const; + + /// + /// Return the "waitQueueTimeoutMS" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) wait_queue_timeout_ms() const; + + /// + /// Return the "zlibCompressionLevel" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) zlib_compression_level() const; + + /// + /// Errors codes which may be returned by @ref mongocxx::v1::uri. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class errc { + zero, ///< Zero. + set_failure, ///< Failed to set the requested URI option. + }; + + /// + /// The error category for @ref mongocxx::v1::uri::errc. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category(); + + /// + /// Support implicit conversion to `std::error_code`. + /// + /// @attention This feature is experimental! It is not ready for use! + /// + friend std::error_code make_error_code(errc v) { + return {static_cast(v), error_category()}; + } +}; + +BSONCXX_PRIVATE_INLINE_CXX17 constexpr char const* uri::k_default_uri; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/include/mongocxx/v1/write_concern.hpp b/src/mongocxx/include/mongocxx/v1/write_concern.hpp index aa07b17b3e..b51b3671c6 100644 --- a/src/mongocxx/include/mongocxx/v1/write_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/write_concern.hpp @@ -20,18 +20,253 @@ #include +#include + +#include +#include + +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { /// /// Options related to a MongoDB Write Concern. /// +/// Supported fields include: +/// - `journal` ("j") +/// - `level` ("w") +/// - `timeout` ("wtimeout") +/// /// @see /// - [Write Concern (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/write-concern/) /// /// @attention This feature is experimental! It is not ready for use! /// -class write_concern {}; +class write_concern { + private: + class impl; + std::unique_ptr _impl; + + public: + /// + /// The write concern level. + /// + /// @see + /// - [Write Concern (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/write-concern/) + /// + /// @attention This feature is experimental! It is not ready for use! + /// + enum class level { + /// + /// [Default MongoDB Read Concerns/Write Concerns (MongoDB + /// Manual)](https://www.mongodb.com/docs/manual/reference/mongodb-defaults/) + /// + k_default, + + /// + /// [`"w": "majority"`](https://www.mongodb.com/docs/manual/reference/write-concern/) + /// + k_majority, + + /// + /// [`"w": ""`](https://www.mongodb.com/docs/manual/reference/write-concern/) + /// + k_tag, + + /// + /// [`"w": 0`](https://www.mongodb.com/docs/manual/reference/write-concern/) + /// + k_unacknowledged, + + /// + /// [`"w": 1`](https://www.mongodb.com/docs/manual/reference/write-concern/) + /// + k_acknowledged, + + /// + /// An unknown (unsupported) write concern level. + /// + /// @note Not to be confused with @ref k_default. + /// + k_unknown, + }; + + /// + /// Destroy this object. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~write_concern(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() write_concern(write_concern&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) operator=(write_concern&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() write_concern(write_concern const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) operator=(write_concern const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() write_concern(); + + /// + /// Set the "w" field as to acknowledgement level. + /// + /// @param v One of: + /// - k_default + /// - k_majority + /// - k_unacknowledged + /// - k_acknowledged + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) acknowledge_level(level v); + + /// + /// Return the current "w" field as an acknowledgement level. + /// + /// @returns + /// - @ref k_default when "w" is unset. + /// - @ref k_majority when `"w": "majority"`. + /// - @ref k_tag when `"w": `. + /// - @ref k_unacknowledged when `"w": 0`. + /// - @ref k_acknowledged when `"w": n` and `n >= 1`. + /// - @ref k_unknown for all other (unsupported) values. + /// + MONGOCXX_ABI_EXPORT_CDECL(level) acknowledge_level() const; + + /// + /// Equivalent to `this->acknowledge_level(level::k_majority)`. + /// + write_concern& majority() { + return this->acknowledge_level(level::k_majority); + } + + /// + /// Equivalent to `this->acknowledge_level(k_majority).timeout(timeout)`. + /// + write_concern& majority(std::chrono::milliseconds v) { + return this->acknowledge_level(level::k_majority).timeout(v); + } + + /// + /// Set the "wtimeout" field. + /// + /// @note `0` is equivalent to "unset". + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) timeout(std::chrono::milliseconds v); + + /// + /// Return the current "wtimeout" field. + /// + /// @note `0` is equivalent to "unset". + /// + MONGOCXX_ABI_EXPORT_CDECL(std::chrono::milliseconds) timeout() const; + + /// + /// Set the "w" field to an integer. + /// + /// @param v + /// - `0` is equivalent to `this->acknowledge_level(k_unacknowledged)`. + /// - `1` is equivalent to `this->acknowledge_level(k_acknowledged)`. + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) nodes(std::int32_t v); + + /// + /// Return the current "w" field as an integer. + /// + /// @returns Empty when `this->acknowledge_level()` is not @ref k_unacknowledged or @ref k_acknowledged. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) nodes() const; + + /// + /// Set the "w" field to a custom write concern name. + /// + /// @{ + write_concern& tag(bsoncxx::v1::stdx::string_view v) { + return this->tag(std::string(v).c_str()); + } + + write_concern& tag(std::string const& v) { + return this->tag(v.c_str()); + } + /// @} + /// + + /// + /// Set the "w" field to a custom write concern name. + /// + /// @param v Equivalent to `this->acknowledge_level(level::k_default)` when `v == nullptr`. + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) tag(char const* v); + + /// + /// Return the current "w" value as a custom write concern name. + /// + /// @returns Empty when `this->acknowledge_level()` is not @ref k_tag. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tag() const; + + /// + /// Set the "j" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) journal(bool j); + + /// + /// Return the current "j" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) journal() const; + + /// + /// Return true when this write concern requires acknowledgement. + /// + MONGOCXX_ABI_EXPORT_CDECL(bool) is_acknowledged() const; + + /// + /// Return this write concern option as a document. + /// + /// @par Preconditions: + /// - `this->acknowledge_level() != level::k_unknown`. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::value) to_document() const; + + /// + /// Compare equal when all supported fields compare equal. + /// + /// @{ + friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(write_concern const& lhs, write_concern const& rhs); + + friend bool operator!=(write_concern const& lhs, write_concern const& rhs) { + return !(lhs == rhs); + } + /// @} + /// +}; } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/lib/mongocxx/v1/server_error.cpp b/src/mongocxx/lib/mongocxx/v1/server_error.cpp index 4e03449e62..6a78cb0cb9 100644 --- a/src/mongocxx/lib/mongocxx/v1/server_error.cpp +++ b/src/mongocxx/lib/mongocxx/v1/server_error.cpp @@ -13,3 +13,18 @@ // limitations under the License. #include + +namespace mongocxx { +namespace v1 { + +class server_error::impl {}; + +server_error::~server_error() = default; + +bool server_error::has_error_label(char const* label) const { + (void)label; + return false; +} + +} // namespace v1 +} // namespace mongocxx From 60d1a1325a7cc8db0f5e685c8c1a2be0c0d4ba3a Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 9 Oct 2025 11:35:19 -0500 Subject: [PATCH 03/33] Revert stray update to comment in macros.hpp --- src/mongocxx/include/mongocxx/v1/detail/macros.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/detail/macros.hpp b/src/mongocxx/include/mongocxx/v1/detail/macros.hpp index 8e841be843..1e50fa51e0 100644 --- a/src/mongocxx/include/mongocxx/v1/detail/macros.hpp +++ b/src/mongocxx/include/mongocxx/v1/detail/macros.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Traditional include guard is required to support v1 include-via-prelude. +// Traditional include guard is required to support v_noabi include-via-prelude. #if !defined(MONGOCXX_V1_DETAIL_MACROS_HPP) #define MONGOCXX_V1_DETAIL_MACROS_HPP From 65ee4ff6d8d95ac850cd451a9975623f650a8245 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Fri, 10 Oct 2025 14:51:17 -0500 Subject: [PATCH 04/33] Fix ownership of `v1::collection::find_one_and_*` return values --- src/mongocxx/include/mongocxx/v1/collection.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/collection.hpp b/src/mongocxx/include/mongocxx/v1/collection.hpp index 3696a01fe3..c7b3d261b8 100644 --- a/src/mongocxx/include/mongocxx/v1/collection.hpp +++ b/src/mongocxx/include/mongocxx/v1/collection.hpp @@ -481,11 +481,11 @@ class collection { /// - [`findAndModify` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/findAndModify/) /// /// @{ - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_delete( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_delete( bsoncxx::v1::document::view query, v1::find_one_and_delete_options const& opts = {}); - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_delete( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_delete( v1::client_session const& session, bsoncxx::v1::document::view query, v1::find_one_and_delete_options const& opts = {}); @@ -505,12 +505,12 @@ class collection { /// - [`findAndModify` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/findAndModify/) /// /// @{ - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_replace( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_replace( bsoncxx::v1::document::view query, bsoncxx::v1::document::value replacement, v1::find_one_and_replace_options const& opts = {}); - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_replace( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_replace( v1::client_session const& session, bsoncxx::v1::document::view query, bsoncxx::v1::document::value update, @@ -531,23 +531,23 @@ class collection { /// - [`findAndModify` (database command) (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/command/findAndModify/) /// /// @{ - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( bsoncxx::v1::document::view query, bsoncxx::v1::document::view update, v1::find_one_and_update_options const& opts = {}); - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( bsoncxx::v1::document::view query, v1::pipeline const& update, v1::find_one_and_update_options const& opts = {}); - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( v1::client_session const& session, bsoncxx::v1::document::view query, bsoncxx::v1::document::view update, v1::find_one_and_update_options const& opts = {}); - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) find_one_and_update( v1::client_session const& session, bsoncxx::v1::document::view query, v1::pipeline const& update, From 11c7cec08bffaa0a94f70ba07a92e259b0daee28 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:24 -0500 Subject: [PATCH 05/33] Add missing documentation for "v" field --- src/mongocxx/include/mongocxx/v1/indexes.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mongocxx/include/mongocxx/v1/indexes.hpp b/src/mongocxx/include/mongocxx/v1/indexes.hpp index 9dc02eb69b..cc66ab8fad 100644 --- a/src/mongocxx/include/mongocxx/v1/indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/indexes.hpp @@ -161,6 +161,7 @@ class indexes { /// - `twod_location_min` ("min") /// - `twod_sphere_version` ("2dsphereIndexVersion") /// - `unique` + /// - `version` ("v") /// - `weights` /// - `write_concern` ("writeConcern") /// From 92711e179e7510993170c6ef2637c2dceb9c6c68 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:24 -0500 Subject: [PATCH 06/33] Fix typos --- src/mongocxx/include/mongocxx/v1/events/command_started.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/events/command_started.hpp b/src/mongocxx/include/mongocxx/v1/events/command_started.hpp index 17a5522363..ff9032b5dc 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_started.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_started.hpp @@ -69,7 +69,7 @@ class command_started { MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) request_id() const; /// - /// Return the cklient-generated operation ID. + /// Return the client-generated operation ID. /// MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) operation_id() const; From 4a53140ea58f50faea3a0170499e1a2d448d7ada Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:24 -0500 Subject: [PATCH 07/33] Return round_trip_time as Optional --- src/mongocxx/include/mongocxx/v1/events/server_description.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/events/server_description.hpp b/src/mongocxx/include/mongocxx/v1/events/server_description.hpp index 818c74d764..6f025e2c0d 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_description.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_description.hpp @@ -22,6 +22,7 @@ #include +#include #include #include @@ -90,7 +91,7 @@ class server_description { /// /// Return the client-measured execution time of the "hello" command. /// - MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) round_trip_time() const; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) round_trip_time() const; /// /// Return the topology type. From e9060f13fe9a174f246511eecd641065b25da7b3 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 08/33] Define `awaited()` in terms of "streaming" vs. "polling" protocols --- .../include/mongocxx/v1/events/server_heartbeat_failed.hpp | 5 ++++- .../include/mongocxx/v1/events/server_heartbeat_started.hpp | 5 ++++- .../mongocxx/v1/events/server_heartbeat_succeeded.hpp | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp index 7aaab55b96..ca093a0951 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp @@ -65,7 +65,10 @@ class server_heartbeat_failed { MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; /// - /// Return true when this heartbeat event is for an awaitable "hello" (instead of a "legacy" hello). + /// Return true when this heartbeat event used the "streaming" protocol (instead of the "polling" protocol). + /// + /// @see + /// - [Server Monitoring (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/server-discovery-and-monitoring/server-monitoring/) /// MONGOCXX_ABI_EXPORT_CDECL(bool) awaited() const; diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp index 942670fd1d..f71c1f023c 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp @@ -55,7 +55,10 @@ class server_heartbeat_started { MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; /// - /// Return true when this heartbeat event is for an awaitable "hello" (instead of a "legacy" hello). + /// Return true when this heartbeat event used the "streaming" protocol (instead of the "polling" protocol). + /// + /// @see + /// - [Server Monitoring (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/server-discovery-and-monitoring/server-monitoring/) /// MONGOCXX_ABI_EXPORT_CDECL(bool) awaited() const; diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp index 4c1ed08328..f220393b08 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp @@ -67,7 +67,10 @@ class server_heartbeat_succeeded { MONGOCXX_ABI_EXPORT_CDECL(std::uint16_t) port() const; /// - /// Return true when this heartbeat event is for an awaitable "hello" (instead of a "legacy" hello). + /// Return true when this heartbeat event used the "streaming" protocol (instead of the "polling" protocol). + /// + /// @see + /// - [Server Monitoring (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/server-discovery-and-monitoring/server-monitoring/) /// MONGOCXX_ABI_EXPORT_CDECL(bool) awaited() const; From e5d7a8ed7ef1745bb4cfd83911b610b206a96cfa Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 09/33] Remove `close()` note from `upload_from_stream()` docs --- src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp index 8f607d24d9..25e96fdcaa 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp @@ -155,8 +155,6 @@ class bucket { /// /// Equivalent to @ref upload_from_stream_with_id with a file ID generated using @ref bsoncxx::v1::oid. /// - /// @note The file is not completely uploaded until @ref mongocxx::v1::gridfs::uploader::close() is invoked. - /// /// @{ MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::upload_result) upload_from_stream( bsoncxx::v1::stdx::string_view filename, From c24b0d8fc8710bb73f0147f8b1eeda69af29cbc4 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 10/33] Fix parameter name --- src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp index 25e96fdcaa..68942942e9 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp @@ -226,7 +226,7 @@ class bucket { MONGOCXX_ABI_EXPORT_CDECL(void) download_to_stream(bsoncxx::v1::types::view id, std::ostream& output); MONGOCXX_ABI_EXPORT_CDECL(void) - download_to_stream(v1::client_session const& session, bsoncxx::v1::types::view id, std::ostream& destination); + download_to_stream(v1::client_session const& session, bsoncxx::v1::types::view id, std::ostream& output); /// @} /// From f8c248926a9630548e4c56473778f6831d486d9a Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 11/33] Remove NTBS overloads in favor of string_view only --- .../include/mongocxx/v1/read_concern.hpp | 23 ++----------------- .../include/mongocxx/v1/server_error.hpp | 14 +---------- src/mongocxx/include/mongocxx/v1/uri.hpp | 9 +------- .../include/mongocxx/v1/write_concern.hpp | 19 ++------------- src/mongocxx/lib/mongocxx/v1/server_error.cpp | 5 ---- 5 files changed, 6 insertions(+), 64 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/read_concern.hpp b/src/mongocxx/include/mongocxx/v1/read_concern.hpp index efd8aedf84..d436f8ce35 100644 --- a/src/mongocxx/include/mongocxx/v1/read_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_concern.hpp @@ -27,7 +27,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -164,27 +163,9 @@ class read_concern { /// /// Set the read concern level to an arbitrary string. /// - /// @param v Equivalent to `this->acknowledge_level(k_server_default)` when `v.empty()`. + /// @param v Equivalent to `this->acknowledge_level(k_server_default)` when `v` is empty. /// - /// @{ - read_concern& acknowledge_string(bsoncxx::v1::stdx::string_view v) { - this->acknowledge_string(v.empty() ? nullptr : std::string(v).c_str()); - return *this; - } - - read_concern& acknowledge_string(std::string const& v) { - this->acknowledge_string(v.empty() ? nullptr : v.c_str()); - return *this; - } - /// @} - /// - - /// - /// Set the read concern level to an arbitrary string. - /// - /// @param v Equivalent to `this->acknowledge_level(k_server_default)` when `v == nullptr`. - /// - MONGOCXX_ABI_EXPORT_CDECL(read_concern&) acknowledge_string(char const* v); + MONGOCXX_ABI_EXPORT_CDECL(read_concern&) acknowledge_string(bsoncxx::v1::stdx::string_view v); /// /// Return the current read concern level as a string. diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index 0364fb82f5..c15b2da63c 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -28,7 +28,6 @@ #include #include -#include #include namespace mongocxx { @@ -104,18 +103,7 @@ class server_error : public v1::exception { /// /// @important The set of error labels may vary depending on the operation and error. /// - /// @{ - bool MONGOCXX_ABI_CDECL has_error_label(char const* label) const; - - bool has_error_label(std::string const& label) const { - return this->has_error_label(label.c_str()); - } - - bool has_error_label(bsoncxx::v1::stdx::string_view label) const { - return this->has_error_label(std::string(label).c_str()); - } - /// @} - /// + bool MONGOCXX_ABI_CDECL has_error_label(bsoncxx::v1::stdx::string_view label) const; }; } // namespace v1 diff --git a/src/mongocxx/include/mongocxx/v1/uri.hpp b/src/mongocxx/include/mongocxx/v1/uri.hpp index 81b8e238d3..dc637a76da 100644 --- a/src/mongocxx/include/mongocxx/v1/uri.hpp +++ b/src/mongocxx/include/mongocxx/v1/uri.hpp @@ -161,14 +161,7 @@ class uri { /// /// @throws mongocxx::v1::exception if a client-side error is encountered. /// - /// @{ - /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() uri(char const* v); - - /* explicit(false) */ uri(bsoncxx::v1::stdx::string_view v) : uri{std::string{v}.c_str()} {} - - /* explicit(false) */ uri(std::string v) : uri{v.c_str()} {} - /// @} - /// + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() uri(bsoncxx::v1::stdx::string_view v); /// /// Return the "authMechanism" option. diff --git a/src/mongocxx/include/mongocxx/v1/write_concern.hpp b/src/mongocxx/include/mongocxx/v1/write_concern.hpp index b51b3671c6..767bc4d769 100644 --- a/src/mongocxx/include/mongocxx/v1/write_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/write_concern.hpp @@ -30,7 +30,6 @@ #include #include #include -#include namespace mongocxx { namespace v1 { @@ -207,23 +206,9 @@ class write_concern { /// /// Set the "w" field to a custom write concern name. /// - /// @{ - write_concern& tag(bsoncxx::v1::stdx::string_view v) { - return this->tag(std::string(v).c_str()); - } - - write_concern& tag(std::string const& v) { - return this->tag(v.c_str()); - } - /// @} - /// - - /// - /// Set the "w" field to a custom write concern name. - /// - /// @param v Equivalent to `this->acknowledge_level(level::k_default)` when `v == nullptr`. + /// @param v Equivalent to `this->acknowledge_level(level::k_default)` when `v` is empty. /// - MONGOCXX_ABI_EXPORT_CDECL(write_concern&) tag(char const* v); + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) tag(bsoncxx::v1::stdx::string_view v); /// /// Return the current "w" value as a custom write concern name. diff --git a/src/mongocxx/lib/mongocxx/v1/server_error.cpp b/src/mongocxx/lib/mongocxx/v1/server_error.cpp index 6a78cb0cb9..ac466d5516 100644 --- a/src/mongocxx/lib/mongocxx/v1/server_error.cpp +++ b/src/mongocxx/lib/mongocxx/v1/server_error.cpp @@ -21,10 +21,5 @@ class server_error::impl {}; server_error::~server_error() = default; -bool server_error::has_error_label(char const* label) const { - (void)label; - return false; -} - } // namespace v1 } // namespace mongocxx From b6971a03fd9a6b93e47a2e669601a11bfd15f001 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 12/33] Avoid more string allocations --- src/mongocxx/include/mongocxx/v1/uri.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/uri.hpp b/src/mongocxx/include/mongocxx/v1/uri.hpp index dc637a76da..9da52516e4 100644 --- a/src/mongocxx/include/mongocxx/v1/uri.hpp +++ b/src/mongocxx/include/mongocxx/v1/uri.hpp @@ -166,12 +166,12 @@ class uri { /// /// Return the "authMechanism" option. /// - MONGOCXX_ABI_EXPORT_CDECL(std::string) auth_mechanism() const; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) auth_mechanism() const; /// /// Return the "authSource" option. /// - MONGOCXX_ABI_EXPORT_CDECL(std::string) auth_source() const; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) auth_source() const; /// /// Return the host(s) identifiers specified by the connection string. @@ -183,7 +183,7 @@ class uri { /// /// @returns Empty when no database name was specified. /// - MONGOCXX_ABI_EXPORT_CDECL(std::string) database() const; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) database() const; /// /// Return all URI options that were specified by the connection string. @@ -193,7 +193,7 @@ class uri { /// /// Return the password specified by the connection string. /// - MONGOCXX_ABI_EXPORT_CDECL(std::string) password() const; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) password() const; /// /// Return the "readConcern" option. @@ -208,7 +208,7 @@ class uri { /// /// Return the "replicaSet" option. /// - MONGOCXX_ABI_EXPORT_CDECL(std::string) replica_set() const; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) replica_set() const; /// /// Return the "tls" option. @@ -223,7 +223,7 @@ class uri { /// /// Return the username specified by the connection string. /// - MONGOCXX_ABI_EXPORT_CDECL(std::string) username() const; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) username() const; /// /// Return the "writeConcern" option. From 452084034fe480b07e06de3f3281cffd34ba37f2 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 13/33] Migrate deprecated `.hedge()` to v1::read_preference --- .../include/mongocxx/v1/read_preference.hpp | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/read_preference.hpp b/src/mongocxx/include/mongocxx/v1/read_preference.hpp index ef0ef3a23b..27d5ec381b 100644 --- a/src/mongocxx/include/mongocxx/v1/read_preference.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_preference.hpp @@ -37,6 +37,7 @@ namespace v1 { /// Options related to a MongoDB Read Preference. /// /// Supported fields include: +/// - `hedge` /// - `max_staleness` ("maxStalenessSeconds") /// - `mode` /// - `tags` ("tag_sets") @@ -122,12 +123,25 @@ class read_preference { /// Default initialization. /// /// @par Postconditions: - /// - `this->mode() == k_primary` - /// - `this->tags().empty() == true` - /// - `this->max_staleness().has_value() == false` + /// - All supported fields are "unset" or zero-initialized. /// MONGOCXX_ABI_EXPORT_CDECL() read_preference(); + /// + /// Set the "hedge" field. + /// + /// @deprecated Deprecated in MongoDB Server version 8.0. + /// + MONGOCXX_DEPRECATED MONGOCXX_ABI_EXPORT_CDECL(read_preference&) hedge(bsoncxx::v1::document::view v); + + /// + /// Return the current "hedge" field. + /// + /// @deprecated Deprecated in MongoDB Server version 8.0. + /// + MONGOCXX_DEPRECATED MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hedge() + const; + /// /// Set the "mode" field. /// From a047d5cf553549a04a8e996876bf581a5946c517 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 14/33] Fix v1::indexes assignment return type --- src/mongocxx/include/mongocxx/v1/indexes.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/indexes.hpp b/src/mongocxx/include/mongocxx/v1/indexes.hpp index cc66ab8fad..536a730839 100644 --- a/src/mongocxx/include/mongocxx/v1/indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/indexes.hpp @@ -467,7 +467,7 @@ class indexes { /// /// Copy assignment. /// - options& operator=(indexes const& other); + indexes& operator=(indexes const& other); /// /// Return all indexes in the associated collection. From bb4056c63dab57e6ed2ae28bc51ff6a6084cd5fa Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 15/33] Replace `std::unique_ptr` with `void*` --- .../include/mongocxx/v1/aggregate_options.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/apm.hpp | 3 +-- .../include/mongocxx/v1/auto_encryption.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/bulk_write.hpp | 17 ++++++++--------- .../include/mongocxx/v1/change_stream.hpp | 8 +++----- src/mongocxx/include/mongocxx/v1/client.hpp | 5 ++--- .../include/mongocxx/v1/client_encryption.hpp | 6 ++---- .../include/mongocxx/v1/client_session.hpp | 6 ++---- src/mongocxx/include/mongocxx/v1/collection.hpp | 3 +-- .../include/mongocxx/v1/count_options.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/cursor.hpp | 6 ++---- src/mongocxx/include/mongocxx/v1/data_key.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/database.hpp | 3 +-- .../include/mongocxx/v1/delete_many_options.hpp | 4 +--- .../include/mongocxx/v1/delete_many_result.hpp | 2 +- .../include/mongocxx/v1/delete_one_options.hpp | 4 +--- .../include/mongocxx/v1/delete_one_result.hpp | 2 +- .../include/mongocxx/v1/distinct_options.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/encrypt.hpp | 3 +-- .../v1/estimated_document_count_options.hpp | 3 +-- .../mongocxx/v1/events/command_failed.hpp | 3 +-- .../mongocxx/v1/events/command_started.hpp | 3 +-- .../mongocxx/v1/events/command_succeeded.hpp | 2 +- .../mongocxx/v1/events/server_closed.hpp | 3 +-- .../mongocxx/v1/events/server_description.hpp | 4 +--- .../v1/events/server_description_changed.hpp | 3 +-- .../v1/events/server_heartbeat_failed.hpp | 3 +-- .../v1/events/server_heartbeat_started.hpp | 3 +-- .../v1/events/server_heartbeat_succeeded.hpp | 3 +-- .../mongocxx/v1/events/server_opening.hpp | 3 +-- .../mongocxx/v1/events/topology_closed.hpp | 4 +--- .../mongocxx/v1/events/topology_description.hpp | 3 +-- .../v1/events/topology_description_changed.hpp | 4 +--- .../mongocxx/v1/events/topology_opening.hpp | 4 +--- .../mongocxx/v1/find_one_and_delete_options.hpp | 3 +-- .../v1/find_one_and_replace_options.hpp | 3 +-- .../mongocxx/v1/find_one_and_update_options.hpp | 3 +-- .../include/mongocxx/v1/find_options.hpp | 3 +-- .../include/mongocxx/v1/gridfs/bucket.hpp | 5 ++--- .../include/mongocxx/v1/gridfs/downloader.hpp | 3 +-- .../mongocxx/v1/gridfs/upload_options.hpp | 3 +-- .../mongocxx/v1/gridfs/upload_result.hpp | 4 +--- .../include/mongocxx/v1/gridfs/uploader.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/hint.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/indexes.hpp | 7 +++---- .../include/mongocxx/v1/insert_many_options.hpp | 4 +--- .../include/mongocxx/v1/insert_many_result.hpp | 3 +-- .../include/mongocxx/v1/insert_one_options.hpp | 4 +--- .../include/mongocxx/v1/insert_one_result.hpp | 4 +--- src/mongocxx/include/mongocxx/v1/pipeline.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/pool.hpp | 7 +++---- src/mongocxx/include/mongocxx/v1/range.hpp | 3 +-- .../include/mongocxx/v1/read_concern.hpp | 5 +---- .../include/mongocxx/v1/read_preference.hpp | 4 +--- .../include/mongocxx/v1/replace_one_options.hpp | 4 +--- .../include/mongocxx/v1/replace_one_result.hpp | 3 +-- .../mongocxx/v1/rewrap_many_datakey_options.hpp | 4 +--- .../mongocxx/v1/rewrap_many_datakey_result.hpp | 4 +--- .../include/mongocxx/v1/search_indexes.hpp | 5 ++--- src/mongocxx/include/mongocxx/v1/server_api.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/tls.hpp | 3 +-- .../include/mongocxx/v1/transaction.hpp | 4 +--- .../include/mongocxx/v1/update_many_options.hpp | 4 +--- .../include/mongocxx/v1/update_many_result.hpp | 3 +-- .../include/mongocxx/v1/update_one_options.hpp | 4 +--- .../include/mongocxx/v1/update_one_result.hpp | 3 +-- src/mongocxx/include/mongocxx/v1/uri.hpp | 4 +--- .../include/mongocxx/v1/write_concern.hpp | 4 +--- 68 files changed, 87 insertions(+), 177 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp b/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp index bb9cb08c67..68742c91fe 100644 --- a/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp @@ -36,7 +36,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -65,7 +64,7 @@ namespace v1 { class aggregate_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/apm.hpp b/src/mongocxx/include/mongocxx/v1/apm.hpp index fb27526226..cb9195b363 100644 --- a/src/mongocxx/include/mongocxx/v1/apm.hpp +++ b/src/mongocxx/include/mongocxx/v1/apm.hpp @@ -38,7 +38,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -54,7 +53,7 @@ namespace v1 { class apm { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp b/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp index 7f5b2055f9..dbc554560d 100644 --- a/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp +++ b/src/mongocxx/include/mongocxx/v1/auto_encryption.hpp @@ -30,7 +30,6 @@ #include -#include #include #include @@ -59,7 +58,7 @@ namespace v1 { class auto_encryption { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp index 96a4620b3c..fff176e0de 100644 --- a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp +++ b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp @@ -36,7 +36,6 @@ #include #include -#include #include namespace mongocxx { @@ -169,7 +168,7 @@ class bulk_write::insert_one { class bulk_write::update_one { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -299,7 +298,7 @@ class bulk_write::update_one { class bulk_write::update_many { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -418,7 +417,7 @@ class bulk_write::update_many { class bulk_write::replace_one { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -531,7 +530,7 @@ class bulk_write::replace_one { class bulk_write::delete_one { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -617,7 +616,7 @@ class bulk_write::delete_one { class bulk_write::delete_many { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -699,7 +698,7 @@ class bulk_write::delete_many { class bulk_write::single { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -845,7 +844,7 @@ class bulk_write::single { class bulk_write::options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -965,7 +964,7 @@ class bulk_write::options { class bulk_write::result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/change_stream.hpp b/src/mongocxx/include/mongocxx/v1/change_stream.hpp index 327118ed9b..3ce888478c 100644 --- a/src/mongocxx/include/mongocxx/v1/change_stream.hpp +++ b/src/mongocxx/include/mongocxx/v1/change_stream.hpp @@ -34,7 +34,6 @@ #include #include #include -#include #include namespace mongocxx { @@ -51,7 +50,7 @@ namespace v1 { class change_stream { private: class impl; - std::unique_ptr _impl; + void* _impl; public: class options; @@ -136,7 +135,7 @@ class change_stream { class change_stream::options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -292,8 +291,7 @@ class change_stream::options { /// class change_stream::iterator { private: - class impl; - std::unique_ptr _impl; + void* _impl; // v1::change_stream public: /// diff --git a/src/mongocxx/include/mongocxx/v1/client.hpp b/src/mongocxx/include/mongocxx/v1/client.hpp index 7e2d42bbac..e581ae22cb 100644 --- a/src/mongocxx/include/mongocxx/v1/client.hpp +++ b/src/mongocxx/include/mongocxx/v1/client.hpp @@ -37,7 +37,6 @@ #include #include -#include #include #include @@ -58,7 +57,7 @@ namespace v1 { class client { private: class impl; - std::unique_ptr _impl; + void* _impl; public: class options; @@ -274,7 +273,7 @@ class client { class client::options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp index bb9a4a5c81..71ff40abe8 100644 --- a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp @@ -40,7 +40,6 @@ #include -#include #include #include @@ -62,8 +61,7 @@ namespace v1 { /// class client_encryption { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_client_encryption_t public: class options; @@ -290,7 +288,7 @@ class client_encryption { class client_encryption::options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/client_session.hpp b/src/mongocxx/include/mongocxx/v1/client_session.hpp index 8ad12c159a..185ae34960 100644 --- a/src/mongocxx/include/mongocxx/v1/client_session.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_session.hpp @@ -32,7 +32,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -49,7 +48,7 @@ namespace v1 { class client_session { private: class impl; - std::unique_ptr _impl; + void* _impl; public: class options; @@ -310,8 +309,7 @@ class client_session { /// class client_session::options { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_session_opt_t public: /// diff --git a/src/mongocxx/include/mongocxx/v1/collection.hpp b/src/mongocxx/include/mongocxx/v1/collection.hpp index c7b3d261b8..a683088689 100644 --- a/src/mongocxx/include/mongocxx/v1/collection.hpp +++ b/src/mongocxx/include/mongocxx/v1/collection.hpp @@ -60,7 +60,6 @@ #include #include -#include #include #include #include @@ -79,7 +78,7 @@ namespace v1 { class collection { private: class impl; - std::unique_ptr _impl; + void* _impl; template using has_begin_expr = decltype((std::declval().begin())); diff --git a/src/mongocxx/include/mongocxx/v1/count_options.hpp b/src/mongocxx/include/mongocxx/v1/count_options.hpp index cc5142ccc3..d6bdf501e9 100644 --- a/src/mongocxx/include/mongocxx/v1/count_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/count_options.hpp @@ -34,7 +34,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -59,7 +58,7 @@ namespace v1 { class count_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/cursor.hpp b/src/mongocxx/include/mongocxx/v1/cursor.hpp index dc93d4d847..02147bebca 100644 --- a/src/mongocxx/include/mongocxx/v1/cursor.hpp +++ b/src/mongocxx/include/mongocxx/v1/cursor.hpp @@ -26,7 +26,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -42,7 +41,7 @@ namespace v1 { class cursor { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -140,8 +139,7 @@ class cursor { /// class cursor::iterator { private: - class impl; - std::unique_ptr _impl; + void* _impl; // v1::cursor public: /// diff --git a/src/mongocxx/include/mongocxx/v1/data_key.hpp b/src/mongocxx/include/mongocxx/v1/data_key.hpp index a8e25b9559..3632f938f9 100644 --- a/src/mongocxx/include/mongocxx/v1/data_key.hpp +++ b/src/mongocxx/include/mongocxx/v1/data_key.hpp @@ -28,7 +28,6 @@ #include #include -#include #include #include @@ -51,7 +50,7 @@ namespace v1 { class data_key { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/database.hpp b/src/mongocxx/include/mongocxx/v1/database.hpp index 8e6d9c6645..16e16831ec 100644 --- a/src/mongocxx/include/mongocxx/v1/database.hpp +++ b/src/mongocxx/include/mongocxx/v1/database.hpp @@ -40,7 +40,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -56,7 +55,7 @@ namespace v1 { class database { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp b/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp index c35bdd0973..56db91b53a 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp @@ -32,8 +32,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -55,7 +53,7 @@ namespace v1 { class delete_many_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp b/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp index 139bbc98cf..2663b88ed5 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp @@ -39,7 +39,7 @@ namespace v1 { class delete_many_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp b/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp index c224bd0831..54813c4a15 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp @@ -32,8 +32,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -55,7 +53,7 @@ namespace v1 { class delete_one_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp b/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp index f75cc3737f..320f12a1dc 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_one_result.hpp @@ -39,7 +39,7 @@ namespace v1 { class delete_one_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/distinct_options.hpp b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp index 5fecaf01b1..26964fad41 100644 --- a/src/mongocxx/include/mongocxx/v1/distinct_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp @@ -32,7 +32,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -52,7 +51,7 @@ namespace v1 { class distinct_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/encrypt.hpp b/src/mongocxx/include/mongocxx/v1/encrypt.hpp index 11758909d9..476fe5c656 100644 --- a/src/mongocxx/include/mongocxx/v1/encrypt.hpp +++ b/src/mongocxx/include/mongocxx/v1/encrypt.hpp @@ -31,7 +31,6 @@ #include #include -#include #include namespace mongocxx { @@ -61,7 +60,7 @@ class encrypt { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp b/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp index 3c152a9f64..f4af9ebf63 100644 --- a/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/estimated_document_count_options.hpp @@ -30,7 +30,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -50,7 +49,7 @@ namespace v1 { class estimated_document_count_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp b/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp index 89c9ae9e21..76c3803753 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp @@ -29,7 +29,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -45,7 +44,7 @@ namespace events { /// class command_failed { private: - void const* _impl; // mongoc_apm_command_failed_t const* + void const* _impl; // mongoc_apm_command_failed_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/command_started.hpp b/src/mongocxx/include/mongocxx/v1/events/command_started.hpp index ff9032b5dc..42cc128b13 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_started.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_started.hpp @@ -29,7 +29,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -45,7 +44,7 @@ namespace events { /// class command_started { private: - void const* _impl; // mongoc_apm_command_started_t const* + void const* _impl; // mongoc_apm_command_started_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp b/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp index 4c287d3712..e3e3a31840 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_succeeded.hpp @@ -44,7 +44,7 @@ namespace events { /// class command_succeeded { private: - void const* _impl; // mongoc_apm_command_succeeded_t const* + void const* _impl; // mongoc_apm_command_succeeded_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp index 7fff29a024..3d6576cc6d 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp @@ -27,7 +27,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -43,7 +42,7 @@ namespace events { /// class server_closed { private: - void const* _impl; // mongoc_apm_server_closed_t const* + void const* _impl; // mongoc_apm_server_closed_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/server_description.hpp b/src/mongocxx/include/mongocxx/v1/events/server_description.hpp index 6f025e2c0d..92b9929ac3 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_description.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_description.hpp @@ -28,7 +28,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -44,8 +43,7 @@ namespace events { /// class server_description { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_server_description_t public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp index 46a9df8de7..bfb14b5da8 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_description_changed.hpp @@ -29,7 +29,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -45,7 +44,7 @@ namespace events { /// class server_description_changed { private: - void const* _impl; // mongoc_apm_server_changed_t const* + void const* _impl; // mongoc_apm_server_changed_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp index ca093a0951..bb96ce7119 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp @@ -25,7 +25,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -41,7 +40,7 @@ namespace events { /// class server_heartbeat_failed { private: - void const* _impl; // mongoc_apm_server_heartbeat_failed_t const* + void const* _impl; // mongoc_apm_server_heartbeat_failed_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp index f71c1f023c..a65d72929b 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_started.hpp @@ -25,7 +25,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -41,7 +40,7 @@ namespace events { /// class server_heartbeat_started { private: - void const* _impl; // mongoc_apm_server_heartbeat_started_t const* + void const* _impl; // mongoc_apm_server_heartbeat_started_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp index f220393b08..847a218732 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_succeeded.hpp @@ -27,7 +27,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -43,7 +42,7 @@ namespace events { /// class server_heartbeat_succeeded { private: - void const* _impl; // mongoc_apm_server_heartbeat_succeeded_t const* + void const* _impl; // mongoc_apm_server_heartbeat_succeeded_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp b/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp index cba6f9a8cd..4ca4fecc53 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp @@ -27,7 +27,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -43,7 +42,7 @@ namespace events { /// class server_opening { private: - void const* _impl; // mongoc_apm_server_opening_t const* + void const* _impl; // mongoc_apm_server_opening_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp index 4ff7187abd..b5c135bb76 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp @@ -26,8 +26,6 @@ #include -#include - namespace mongocxx { namespace v1 { namespace events { @@ -42,7 +40,7 @@ namespace events { /// class topology_closed { private: - void const* _impl; // mongoc_apm_topology_closed_t const* + void const* _impl; // mongoc_apm_topology_closed_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp index a18f84a2e7..deeb062f28 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp @@ -27,7 +27,6 @@ #include -#include #include namespace mongocxx { @@ -44,7 +43,7 @@ namespace events { /// class topology_description { private: - void const* _impl; // mongoc_topology_description_t const* + void const* _impl; // mongoc_topology_description_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp index 88198a2399..db9822205e 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_description_changed.hpp @@ -26,8 +26,6 @@ #include -#include - namespace mongocxx { namespace v1 { namespace events { @@ -42,7 +40,7 @@ namespace events { /// class topology_description_changed { private: - void const* _impl; // mongoc_apm_topology_changed_t const* + void const* _impl; // mongoc_apm_topology_changed_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp b/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp index 7704138db0..435f7dcaf1 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp @@ -26,8 +26,6 @@ #include -#include - namespace mongocxx { namespace v1 { namespace events { @@ -42,7 +40,7 @@ namespace events { /// class topology_opening { private: - void const* _impl; // mongoc_apm_topology_opening_t const* + void const* _impl; // mongoc_apm_topology_opening_t const public: /// diff --git a/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp b/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp index 47f44dbbab..74d3694705 100644 --- a/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp @@ -33,7 +33,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -60,7 +59,7 @@ namespace v1 { class find_one_and_delete_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp b/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp index d9ec449454..ae8a071967 100644 --- a/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_one_and_replace_options.hpp @@ -34,7 +34,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -64,7 +63,7 @@ namespace v1 { class find_one_and_replace_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp b/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp index e885e1a99e..fe4003ca88 100644 --- a/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_one_and_update_options.hpp @@ -36,7 +36,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -67,7 +66,7 @@ namespace v1 { class find_one_and_update_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/find_options.hpp b/src/mongocxx/include/mongocxx/v1/find_options.hpp index 3e05539d25..017a2b5d00 100644 --- a/src/mongocxx/include/mongocxx/v1/find_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_options.hpp @@ -34,7 +34,6 @@ #include #include -#include #include namespace mongocxx { @@ -73,7 +72,7 @@ namespace v1 { class find_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp index 68942942e9..2b4df9b095 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -62,7 +61,7 @@ namespace gridfs { class bucket { private: class impl; - std::unique_ptr _impl; + void* _impl; public: class options; @@ -339,7 +338,7 @@ class bucket { class bucket::options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp index 50e2b46579..81e17f9d4f 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -45,7 +44,7 @@ namespace gridfs { class downloader { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp index b776c0a607..a4b0119e6d 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp @@ -28,7 +28,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -49,7 +48,7 @@ namespace gridfs { class upload_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp index e22d2826dd..1c8e233af9 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp @@ -24,8 +24,6 @@ #include -#include - namespace mongocxx { namespace v1 { namespace gridfs { @@ -44,7 +42,7 @@ namespace gridfs { class upload_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp index f06731db98..8270636bfb 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -45,7 +44,7 @@ namespace gridfs { class uploader { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/hint.hpp b/src/mongocxx/include/mongocxx/v1/hint.hpp index c2ae6490e8..761061cbf3 100644 --- a/src/mongocxx/include/mongocxx/v1/hint.hpp +++ b/src/mongocxx/include/mongocxx/v1/hint.hpp @@ -29,7 +29,6 @@ #include -#include #include namespace mongocxx { @@ -48,7 +47,7 @@ namespace v1 { class hint { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/indexes.hpp b/src/mongocxx/include/mongocxx/v1/indexes.hpp index 536a730839..4341aa4ab6 100644 --- a/src/mongocxx/include/mongocxx/v1/indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/indexes.hpp @@ -33,7 +33,6 @@ #include #include -#include #include #include #include @@ -59,7 +58,7 @@ class indexes { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -80,7 +79,7 @@ class indexes { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -173,7 +172,7 @@ class indexes { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp b/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp index 6694fa58ae..2d8f4b8443 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp @@ -29,8 +29,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -51,7 +49,7 @@ namespace v1 { class insert_many_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp b/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp index a54a8fd75d..2a0142acc3 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp @@ -26,7 +26,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -42,7 +41,7 @@ namespace v1 { class insert_many_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp b/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp index 8b13dd5eb7..0545f4bd0d 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp @@ -29,8 +29,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -50,7 +48,7 @@ namespace v1 { class insert_one_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp b/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp index 4bfbb24cfa..b3198f5cce 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp @@ -25,8 +25,6 @@ #include #include -#include - namespace mongocxx { namespace v1 { @@ -41,7 +39,7 @@ namespace v1 { class insert_one_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/pipeline.hpp b/src/mongocxx/include/mongocxx/v1/pipeline.hpp index 24e7f48c32..77ae225cd5 100644 --- a/src/mongocxx/include/mongocxx/v1/pipeline.hpp +++ b/src/mongocxx/include/mongocxx/v1/pipeline.hpp @@ -28,7 +28,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -44,7 +43,7 @@ namespace v1 { class pipeline { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/pool.hpp b/src/mongocxx/include/mongocxx/v1/pool.hpp index a99a9ab366..f8f1721d76 100644 --- a/src/mongocxx/include/mongocxx/v1/pool.hpp +++ b/src/mongocxx/include/mongocxx/v1/pool.hpp @@ -29,7 +29,6 @@ #include #include -#include #include #include @@ -51,7 +50,7 @@ namespace v1 { class pool { private: class impl; - std::unique_ptr _impl; + void* _impl; public: class options; @@ -175,7 +174,7 @@ class pool { class pool::options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// @@ -236,7 +235,7 @@ class pool::options { class pool::entry { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/range.hpp b/src/mongocxx/include/mongocxx/v1/range.hpp index 756464787b..0c2b0b4405 100644 --- a/src/mongocxx/include/mongocxx/v1/range.hpp +++ b/src/mongocxx/include/mongocxx/v1/range.hpp @@ -28,7 +28,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -52,7 +51,7 @@ namespace v1 { class range { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/read_concern.hpp b/src/mongocxx/include/mongocxx/v1/read_concern.hpp index d436f8ce35..482c2938c1 100644 --- a/src/mongocxx/include/mongocxx/v1/read_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_concern.hpp @@ -26,8 +26,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -45,8 +43,7 @@ namespace v1 { /// class read_concern { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_read_concern_t public: /// diff --git a/src/mongocxx/include/mongocxx/v1/read_preference.hpp b/src/mongocxx/include/mongocxx/v1/read_preference.hpp index 27d5ec381b..181b208c0c 100644 --- a/src/mongocxx/include/mongocxx/v1/read_preference.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_preference.hpp @@ -28,7 +28,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -49,8 +48,7 @@ namespace v1 { /// class read_preference { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_read_prefs_t public: /// diff --git a/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp b/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp index ec3dd0b8ba..484813469f 100644 --- a/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp @@ -32,8 +32,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -58,7 +56,7 @@ namespace v1 { class replace_one_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp b/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp index 32012087bb..4791e897f6 100644 --- a/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp @@ -28,7 +28,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -44,7 +43,7 @@ namespace v1 { class replace_one_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp index 5b8125689b..a782f4743b 100644 --- a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp @@ -28,8 +28,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -48,7 +46,7 @@ namespace v1 { class rewrap_many_datakey_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp index e987dd00ff..db781b22a5 100644 --- a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp @@ -23,8 +23,6 @@ #include #include -#include - namespace mongocxx { namespace v1 { @@ -42,7 +40,7 @@ namespace v1 { class rewrap_many_datakey_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp index 76d943c196..be4c6c5f79 100644 --- a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -51,7 +50,7 @@ namespace v1 { class search_indexes { private: class impl; - std::unique_ptr _impl; + void* _impl; public: class model; @@ -313,7 +312,7 @@ class search_indexes::model { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/server_api.hpp b/src/mongocxx/include/mongocxx/v1/server_api.hpp index afe53ad15f..602ec4b924 100644 --- a/src/mongocxx/include/mongocxx/v1/server_api.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_api.hpp @@ -25,7 +25,6 @@ #include -#include #include #include #include @@ -50,7 +49,7 @@ class server_api { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/tls.hpp b/src/mongocxx/include/mongocxx/v1/tls.hpp index 0197f983c9..cb0a343f79 100644 --- a/src/mongocxx/include/mongocxx/v1/tls.hpp +++ b/src/mongocxx/include/mongocxx/v1/tls.hpp @@ -25,7 +25,6 @@ #include -#include #include namespace mongocxx { @@ -49,7 +48,7 @@ namespace v1 { class tls { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/transaction.hpp b/src/mongocxx/include/mongocxx/v1/transaction.hpp index 9473c6212f..0f6a5f87ad 100644 --- a/src/mongocxx/include/mongocxx/v1/transaction.hpp +++ b/src/mongocxx/include/mongocxx/v1/transaction.hpp @@ -29,7 +29,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -50,8 +49,7 @@ namespace v1 { /// class transaction { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_transaction_opt_t public: /// diff --git a/src/mongocxx/include/mongocxx/v1/update_many_options.hpp b/src/mongocxx/include/mongocxx/v1/update_many_options.hpp index 7f747386e1..70ed13788f 100644 --- a/src/mongocxx/include/mongocxx/v1/update_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_many_options.hpp @@ -34,8 +34,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -61,7 +59,7 @@ namespace v1 { class update_many_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/update_many_result.hpp b/src/mongocxx/include/mongocxx/v1/update_many_result.hpp index 3de3130318..d79e8e06d6 100644 --- a/src/mongocxx/include/mongocxx/v1/update_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_many_result.hpp @@ -29,7 +29,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -45,7 +44,7 @@ namespace v1 { class update_many_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/update_one_options.hpp b/src/mongocxx/include/mongocxx/v1/update_one_options.hpp index 137d378afd..5ebaec0ca9 100644 --- a/src/mongocxx/include/mongocxx/v1/update_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_one_options.hpp @@ -34,8 +34,6 @@ #include -#include - namespace mongocxx { namespace v1 { @@ -61,7 +59,7 @@ namespace v1 { class update_one_options { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/update_one_result.hpp b/src/mongocxx/include/mongocxx/v1/update_one_result.hpp index 6f1b1bdb08..3c2c27da10 100644 --- a/src/mongocxx/include/mongocxx/v1/update_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_one_result.hpp @@ -28,7 +28,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -44,7 +43,7 @@ namespace v1 { class update_one_result { private: class impl; - std::unique_ptr _impl; + void* _impl; public: /// diff --git a/src/mongocxx/include/mongocxx/v1/uri.hpp b/src/mongocxx/include/mongocxx/v1/uri.hpp index 9da52516e4..7bfeba2853 100644 --- a/src/mongocxx/include/mongocxx/v1/uri.hpp +++ b/src/mongocxx/include/mongocxx/v1/uri.hpp @@ -40,7 +40,6 @@ #include #include -#include #include #include #include @@ -95,8 +94,7 @@ namespace v1 { /// class uri { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_uri_t public: /// diff --git a/src/mongocxx/include/mongocxx/v1/write_concern.hpp b/src/mongocxx/include/mongocxx/v1/write_concern.hpp index 767bc4d769..1b1f0aae13 100644 --- a/src/mongocxx/include/mongocxx/v1/write_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/write_concern.hpp @@ -29,7 +29,6 @@ #include #include -#include namespace mongocxx { namespace v1 { @@ -49,8 +48,7 @@ namespace v1 { /// class write_concern { private: - class impl; - std::unique_ptr _impl; + void* _impl; // mongoc_write_concern_t public: /// From 5fe90794ba79c78844d5a50c1aa40de872ce7f07 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:45:25 -0500 Subject: [PATCH 16/33] Fix IWYU missing headers --- src/mongocxx/include/mongocxx/v1/bulk_write.hpp | 2 ++ src/mongocxx/include/mongocxx/v1/collection.hpp | 5 +++++ src/mongocxx/include/mongocxx/v1/database.hpp | 2 ++ .../include/mongocxx/v1/events/server_heartbeat_failed.hpp | 1 + .../include/mongocxx/v1/rewrap_many_datakey_options.hpp | 2 ++ .../include/mongocxx/v1/rewrap_many_datakey_result.hpp | 2 ++ src/mongocxx/include/mongocxx/v1/search_indexes.hpp | 1 + 7 files changed, 15 insertions(+) diff --git a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp index fff176e0de..3d87c3b4b0 100644 --- a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp +++ b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp @@ -20,6 +20,8 @@ #include +#include +#include #include #include diff --git a/src/mongocxx/include/mongocxx/v1/collection.hpp b/src/mongocxx/include/mongocxx/v1/collection.hpp index a683088689..a88e24c89c 100644 --- a/src/mongocxx/include/mongocxx/v1/collection.hpp +++ b/src/mongocxx/include/mongocxx/v1/collection.hpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -36,6 +38,7 @@ #include #include #include +#include #include #include @@ -60,7 +63,9 @@ #include #include +#include #include +#include #include #include diff --git a/src/mongocxx/include/mongocxx/v1/database.hpp b/src/mongocxx/include/mongocxx/v1/database.hpp index 16e16831ec..16b88d1401 100644 --- a/src/mongocxx/include/mongocxx/v1/database.hpp +++ b/src/mongocxx/include/mongocxx/v1/database.hpp @@ -40,6 +40,8 @@ #include #include +#include +#include namespace mongocxx { namespace v1 { diff --git a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp index bb96ce7119..6d881551d7 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_heartbeat_failed.hpp @@ -25,6 +25,7 @@ #include #include +#include namespace mongocxx { namespace v1 { diff --git a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp index a782f4743b..2833891285 100644 --- a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_options.hpp @@ -28,6 +28,8 @@ #include +#include + namespace mongocxx { namespace v1 { diff --git a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp index db781b22a5..003a628169 100644 --- a/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/rewrap_many_datakey_result.hpp @@ -20,6 +20,8 @@ #include +#include + #include #include diff --git a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp index be4c6c5f79..d9d4fbc122 100644 --- a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp @@ -26,6 +26,7 @@ #include #include +#include #include #include From 554949c75b7d684f6db538e9af6e32ce8caee495 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 21 Oct 2025 16:56:42 -0500 Subject: [PATCH 17/33] Fix documentation: empty wtag is allowed --- src/mongocxx/include/mongocxx/v1/write_concern.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/write_concern.hpp b/src/mongocxx/include/mongocxx/v1/write_concern.hpp index 1b1f0aae13..b26c8fcb85 100644 --- a/src/mongocxx/include/mongocxx/v1/write_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/write_concern.hpp @@ -204,8 +204,6 @@ class write_concern { /// /// Set the "w" field to a custom write concern name. /// - /// @param v Equivalent to `this->acknowledge_level(level::k_default)` when `v` is empty. - /// MONGOCXX_ABI_EXPORT_CDECL(write_concern&) tag(bsoncxx::v1::stdx::string_view v); /// From ae0530e02df7afe24575f28a97eb4b614a1d5632 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 23 Oct 2025 11:38:23 -0500 Subject: [PATCH 18/33] Use `key_function()` instead of out-of-line default dtor --- src/mongocxx/include/mongocxx/v1/server_error.hpp | 5 ++++- src/mongocxx/lib/mongocxx/v1/server_error.cpp | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index c15b2da63c..e9f1ffb8ee 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -53,7 +53,7 @@ class server_error : public v1::exception { /// /// @warning Invalidates all associated views. /// - ~server_error() override; + ~server_error() override = default; /// /// Move constructor. @@ -104,6 +104,9 @@ class server_error : public v1::exception { /// @important The set of error labels may vary depending on the operation and error. /// bool MONGOCXX_ABI_CDECL has_error_label(bsoncxx::v1::stdx::string_view label) const; + + private: + MONGOCXX_ABI_NO_EXPORT void key_function() const override; }; } // namespace v1 diff --git a/src/mongocxx/lib/mongocxx/v1/server_error.cpp b/src/mongocxx/lib/mongocxx/v1/server_error.cpp index ac466d5516..20f8b061cd 100644 --- a/src/mongocxx/lib/mongocxx/v1/server_error.cpp +++ b/src/mongocxx/lib/mongocxx/v1/server_error.cpp @@ -19,7 +19,14 @@ namespace v1 { class server_error::impl {}; -server_error::~server_error() = default; +// Prevent vague linkage of the vtable and type_info object (-Wweak-vtables). +// - https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable +// > The key function is the first non-pure virtual function that is not inline at the point of class definition. +// - https://lld.llvm.org/missingkeyfunction: +// > It’s always advisable to ensure there is at least one eligible function that can serve as the key function. +// - https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html +// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the vtable. +void server_error::key_function() const {} } // namespace v1 } // namespace mongocxx From c080b1b089ef61faa2e9ee2db8b570eb814ab8cc Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 23 Oct 2025 11:38:23 -0500 Subject: [PATCH 19/33] Silence C4251 and C4275 for v1::server_error --- src/mongocxx/include/mongocxx/v1/server_error.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index e9f1ffb8ee..ae18aa22cf 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -33,6 +33,10 @@ namespace mongocxx { namespace v1 { +BSONCXX_PRIVATE_WARNINGS_PUSH(); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251)); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); + /// /// A MongoDB server error. /// @@ -109,6 +113,8 @@ class server_error : public v1::exception { MONGOCXX_ABI_NO_EXPORT void key_function() const override; }; +BSONCXX_PRIVATE_WARNINGS_POP(); + } // namespace v1 } // namespace mongocxx From bac39f21632f5c649fce7acd66c8fe1c6314e19b Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 23 Oct 2025 11:42:15 -0500 Subject: [PATCH 20/33] IWYU --- src/mongocxx/include/mongocxx/v1/server_error.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index ae18aa22cf..876f94676c 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -22,6 +22,7 @@ #include +#include #include #include From 9b4e7f595ca62f833e91481aabee0afbbe288cd3 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 23 Oct 2025 11:42:39 -0500 Subject: [PATCH 21/33] Formatting --- src/bsoncxx/lib/bsoncxx/v1/exception.cpp | 3 ++- src/mongocxx/lib/mongocxx/v1/exception.cpp | 3 ++- src/mongocxx/lib/mongocxx/v1/server_error.cpp | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bsoncxx/lib/bsoncxx/v1/exception.cpp b/src/bsoncxx/lib/bsoncxx/v1/exception.cpp index 4f656bcffb..0aeb4dcc76 100644 --- a/src/bsoncxx/lib/bsoncxx/v1/exception.cpp +++ b/src/bsoncxx/lib/bsoncxx/v1/exception.cpp @@ -91,7 +91,8 @@ namespace v1 { // - https://lld.llvm.org/missingkeyfunction: // > It’s always advisable to ensure there is at least one eligible function that can serve as the key function. // - https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html -// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the vtable. +// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the +// vtable. void exception::key_function() const {} } // namespace v1 diff --git a/src/mongocxx/lib/mongocxx/v1/exception.cpp b/src/mongocxx/lib/mongocxx/v1/exception.cpp index 5bc0f8e1a3..c76b4d1fb0 100644 --- a/src/mongocxx/lib/mongocxx/v1/exception.cpp +++ b/src/mongocxx/lib/mongocxx/v1/exception.cpp @@ -89,7 +89,8 @@ std::error_category const& type_error_category() { // - https://lld.llvm.org/missingkeyfunction: // > It’s always advisable to ensure there is at least one eligible function that can serve as the key function. // - https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html -// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the vtable. +// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the +// vtable. void exception::key_function() const {} } // namespace v1 diff --git a/src/mongocxx/lib/mongocxx/v1/server_error.cpp b/src/mongocxx/lib/mongocxx/v1/server_error.cpp index 20f8b061cd..1e2e743657 100644 --- a/src/mongocxx/lib/mongocxx/v1/server_error.cpp +++ b/src/mongocxx/lib/mongocxx/v1/server_error.cpp @@ -25,7 +25,8 @@ class server_error::impl {}; // - https://lld.llvm.org/missingkeyfunction: // > It’s always advisable to ensure there is at least one eligible function that can serve as the key function. // - https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html -// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the vtable. +// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the +// vtable. void server_error::key_function() const {} } // namespace v1 From a1580b4926ac20730be886915baeb2f0c4dc5e4d Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Fri, 24 Oct 2025 16:12:53 -0500 Subject: [PATCH 22/33] Address Doxygen 1.15.0 unresolved reference warnings --- .../include/mongocxx/v1/read_concern.hpp | 16 ++++++++-------- .../include/mongocxx/v1/read_preference.hpp | 12 ++++++------ .../include/mongocxx/v1/write_concern.hpp | 19 ++++++++++--------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/read_concern.hpp b/src/mongocxx/include/mongocxx/v1/read_concern.hpp index 482c2938c1..4689f494d7 100644 --- a/src/mongocxx/include/mongocxx/v1/read_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_concern.hpp @@ -81,7 +81,7 @@ class read_concern { /// /// An unknown (unsupported) read concern level. /// - /// @note Not to be confused with @ref k_server_default. + /// @note Not to be confused with @ref level::k_server_default. /// k_unknown, @@ -143,12 +143,12 @@ class read_concern { /// Set the read concern level. /// /// @param v One of: - /// - @ref k_local - /// - @ref k_majority - /// - @ref k_linearizable - /// - @ref k_server_default - /// - @ref k_available - /// - @ref k_snapshot + /// - @ref level::k_local + /// - @ref level::k_majority + /// - @ref level::k_linearizable + /// - @ref level::k_server_default + /// - @ref level::k_available + /// - @ref level::k_snapshot /// MONGOCXX_ABI_EXPORT_CDECL(read_concern&) acknowledge_level(level v); @@ -167,7 +167,7 @@ class read_concern { /// /// Return the current read concern level as a string. /// - /// @returns Empty when `this->acknowledge_level()` is @ref k_server_default or @ref k_unknown. + /// @returns Empty when `this->acknowledge_level()` is @ref level::k_server_default or @ref level::k_unknown. /// MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) acknowledge_string() const; diff --git a/src/mongocxx/include/mongocxx/v1/read_preference.hpp b/src/mongocxx/include/mongocxx/v1/read_preference.hpp index 181b208c0c..bf2d5933f8 100644 --- a/src/mongocxx/include/mongocxx/v1/read_preference.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_preference.hpp @@ -144,12 +144,12 @@ class read_preference { /// Set the "mode" field. /// /// @param v One of: - /// - @ref k_primary - /// - @ref k_primary_preferred - /// - @ref k_secondary - /// - @ref k_secondary_preferred - /// - @ref k_nearest - /// Any unsupported value is interpreted as @ref k_primary. + /// - @ref read_mode::k_primary + /// - @ref read_mode::k_primary_preferred + /// - @ref read_mode::k_secondary + /// - @ref read_mode::k_secondary_preferred + /// - @ref read_mode::k_nearest + /// Any unsupported value is interpreted as @ref read_mode::k_primary. /// /// @see /// - [Read Preference Use Cases](https://www.mongodb.com/docs/manual/core/read-preference-use-cases/) diff --git a/src/mongocxx/include/mongocxx/v1/write_concern.hpp b/src/mongocxx/include/mongocxx/v1/write_concern.hpp index b26c8fcb85..5bc0fabcf9 100644 --- a/src/mongocxx/include/mongocxx/v1/write_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/write_concern.hpp @@ -89,7 +89,7 @@ class write_concern { /// /// An unknown (unsupported) write concern level. /// - /// @note Not to be confused with @ref k_default. + /// @note Not to be confused with @ref level::k_default. /// k_unknown, }; @@ -148,12 +148,12 @@ class write_concern { /// Return the current "w" field as an acknowledgement level. /// /// @returns - /// - @ref k_default when "w" is unset. - /// - @ref k_majority when `"w": "majority"`. - /// - @ref k_tag when `"w": `. - /// - @ref k_unacknowledged when `"w": 0`. - /// - @ref k_acknowledged when `"w": n` and `n >= 1`. - /// - @ref k_unknown for all other (unsupported) values. + /// - @ref level::k_default when "w" is unset. + /// - @ref level::k_majority when `"w": "majority"`. + /// - @ref level::k_tag when `"w": `. + /// - @ref level::k_unacknowledged when `"w": 0`. + /// - @ref level::k_acknowledged when `"w": n` and `n >= 1`. + /// - @ref level::k_unknown for all other (unsupported) values. /// MONGOCXX_ABI_EXPORT_CDECL(level) acknowledge_level() const; @@ -197,7 +197,8 @@ class write_concern { /// /// Return the current "w" field as an integer. /// - /// @returns Empty when `this->acknowledge_level()` is not @ref k_unacknowledged or @ref k_acknowledged. + /// @returns Empty when `this->acknowledge_level()` is not @ref level::k_unacknowledged or @ref + /// level::k_acknowledged. /// MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) nodes() const; @@ -209,7 +210,7 @@ class write_concern { /// /// Return the current "w" value as a custom write concern name. /// - /// @returns Empty when `this->acknowledge_level()` is not @ref k_tag. + /// @returns Empty when `this->acknowledge_level()` is not @ref level::k_tag. /// MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) tag() const; From f755f3966954bacb114e2129d2565e25811f3676 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Fri, 24 Oct 2025 16:12:53 -0500 Subject: [PATCH 23/33] Revert to using dtor as key function for v1::server_error --- src/mongocxx/include/mongocxx/v1/server_error.hpp | 4 ++-- src/mongocxx/lib/mongocxx/v1/server_error.cpp | 10 +--------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index 876f94676c..7945a8f406 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -58,7 +58,7 @@ class server_error : public v1::exception { /// /// @warning Invalidates all associated views. /// - ~server_error() override = default; + ~server_error() override; /// /// Move constructor. @@ -111,7 +111,7 @@ class server_error : public v1::exception { bool MONGOCXX_ABI_CDECL has_error_label(bsoncxx::v1::stdx::string_view label) const; private: - MONGOCXX_ABI_NO_EXPORT void key_function() const override; + void key_function() const override {} }; BSONCXX_PRIVATE_WARNINGS_POP(); diff --git a/src/mongocxx/lib/mongocxx/v1/server_error.cpp b/src/mongocxx/lib/mongocxx/v1/server_error.cpp index 1e2e743657..ac466d5516 100644 --- a/src/mongocxx/lib/mongocxx/v1/server_error.cpp +++ b/src/mongocxx/lib/mongocxx/v1/server_error.cpp @@ -19,15 +19,7 @@ namespace v1 { class server_error::impl {}; -// Prevent vague linkage of the vtable and type_info object (-Wweak-vtables). -// - https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable -// > The key function is the first non-pure virtual function that is not inline at the point of class definition. -// - https://lld.llvm.org/missingkeyfunction: -// > It’s always advisable to ensure there is at least one eligible function that can serve as the key function. -// - https://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html -// > For polymorphic classes (classes with virtual functions), the ‘type_info’ object is written out along with the -// vtable. -void server_error::key_function() const {} +server_error::~server_error() = default; } // namespace v1 } // namespace mongocxx From b56c9ad465ac57f649eb6842b952c83ef2a44909 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 28 Oct 2025 11:47:32 -0500 Subject: [PATCH 24/33] Fix return type for `v1::client_encryption::key_vault_client()` --- src/mongocxx/include/mongocxx/v1/client_encryption.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp index 71ff40abe8..8ebfdfee45 100644 --- a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp @@ -344,7 +344,7 @@ class client_encryption::options { /// /// Return the current "keyVaultClient" field. /// - MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) key_vault_client() const; + MONGOCXX_ABI_EXPORT_CDECL(mongocxx::v1::client*) key_vault_client() const; /// /// The name of a database and a collection. From 40793f342c3139c895c9f39b64b3ae39d43f7b60 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 28 Oct 2025 11:47:32 -0500 Subject: [PATCH 25/33] Rename parameter: pipe -> pipeline --- src/mongocxx/include/mongocxx/v1/database.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/database.hpp b/src/mongocxx/include/mongocxx/v1/database.hpp index 16b88d1401..c876737cb0 100644 --- a/src/mongocxx/include/mongocxx/v1/database.hpp +++ b/src/mongocxx/include/mongocxx/v1/database.hpp @@ -336,11 +336,11 @@ class database { /// /// @{ MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) watch( - v1::pipeline const& pipe, + v1::pipeline const& pipeline, v1::change_stream::options const& opts = {}); MONGOCXX_ABI_EXPORT_CDECL(v1::change_stream) - watch(v1::client_session const& session, v1::pipeline const& pipe, v1::change_stream::options const& opts = {}); + watch(v1::client_session const& session, v1::pipeline const& pipeline, v1::change_stream::options const& opts = {}); /// @} /// }; From 78b395eabddc099eaf4e129cc03eb0c175f6bdeb Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Tue, 28 Oct 2025 11:47:32 -0500 Subject: [PATCH 26/33] Fix, tweak, and improve documentation per PR feedback --- .../include/mongocxx/v1/bulk_write.hpp | 4 +-- src/mongocxx/include/mongocxx/v1/client.hpp | 17 ++++----- .../include/mongocxx/v1/client_encryption.hpp | 8 ++--- .../include/mongocxx/v1/client_session.hpp | 36 ++----------------- .../include/mongocxx/v1/collection.hpp | 4 +-- src/mongocxx/include/mongocxx/v1/database.hpp | 2 +- .../mongocxx/v1/delete_many_options.hpp | 2 +- .../mongocxx/v1/delete_many_result.hpp | 2 +- .../mongocxx/v1/delete_one_options.hpp | 2 +- .../include/mongocxx/v1/distinct_options.hpp | 4 +-- src/mongocxx/include/mongocxx/v1/indexes.hpp | 8 ++--- .../mongocxx/v1/insert_many_result.hpp | 4 +-- src/mongocxx/include/mongocxx/v1/pool.hpp | 12 ++++--- .../mongocxx/v1/replace_one_result.hpp | 2 +- .../include/mongocxx/v1/search_indexes.hpp | 2 +- .../include/mongocxx/v1/server_api.hpp | 3 +- 16 files changed, 40 insertions(+), 72 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp index 3d87c3b4b0..6063e59dc8 100644 --- a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp +++ b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp @@ -956,8 +956,8 @@ class bulk_write::options { /// the CRUD API specification is used to implement the requested operations (see: `MONGOC_WRITE_RESULT_COMPLETE`). /// /// @see +/// - [`mongoc_bulk_operation_t` (mongoc)](https://mongoc.org/libmongoc/current/mongoc_bulk_operation_t.html) /// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) -/// - [Bulk Write API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/bulk-write/) /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) /// @@ -1048,7 +1048,7 @@ class bulk_write::result { MONGOCXX_ABI_EXPORT_CDECL(id_map) upserted_ids() const; /// - /// Compare equal when `lhs.raw()` and `rhs.raw()` compare equal. + /// Compare equal when all supported fields compare equal. /// /// @{ friend MONGOCXX_ABI_EXPORT_CDECL(bool) operator==(result const& lhs, result const& rhs); diff --git a/src/mongocxx/include/mongocxx/v1/client.hpp b/src/mongocxx/include/mongocxx/v1/client.hpp index e581ae22cb..8aea9a0444 100644 --- a/src/mongocxx/include/mongocxx/v1/client.hpp +++ b/src/mongocxx/include/mongocxx/v1/client.hpp @@ -98,11 +98,11 @@ class client { /// /// Initialize with the given URI. /// - /// @par Postconditions: - /// - `*this` is connected to the MongoDB server(s). + /// @note No connection is attempted until the first command executed with this client object or with an associated + /// object obtained from this client object. Server-side errors will only be encountered during or after the first + /// command executed. /// - /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. - /// @throws mongocxx::v1::exception for all other runtime errors. + /// @throws mongocxx::v1::exception when a client-side error is encountered. /// /// @{ MONGOCXX_ABI_EXPORT_CDECL() client(v1::uri uri, options const& opts); @@ -112,13 +112,10 @@ class client { /// /// - /// Initialize with default URI options. + /// Default initialization. /// /// @par Postconditions: - /// - `*this` is connected to the MongoDB server(s). - /// - /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. - /// @throws mongocxx::v1::exception for all other runtime errors. + /// - `*this` is in an assign-or-destroy-only state. /// MONGOCXX_ABI_EXPORT_CDECL() client(); @@ -128,7 +125,7 @@ class client { explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; /// - /// Return the URI options used to initialize this client. + /// Return the @ref mongocxx::v1::uri used to initialize this client. /// MONGOCXX_ABI_EXPORT_CDECL(v1::uri) uri() const; diff --git a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp index 8ebfdfee45..7b8c0c9f87 100644 --- a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp @@ -126,7 +126,7 @@ class client_encryption { /// /// @param db The database within which to create the encrypted collection. /// @param name The name of the new encrypted collection. - /// @param opts "createCollection" options. + /// @param opts "create" options. /// @param coll_opts Set to the options used to create the encrypted collection, including the "encryptedFields" /// field. /// @param kms_provider The KMS provider to use for this operation. @@ -148,7 +148,7 @@ class client_encryption { /// /// @param db The database within which to create the encrypted collection. /// @param name The name of the new encrypted collection. - /// @param opts "createCollection" options. + /// @param opts "create" options. /// @param coll_opts Set to the options used to create the encrypted collection, including the "encryptedFields" /// field. /// @param kms_provider The KMS provider to use for this operation. @@ -253,9 +253,9 @@ class client_encryption { bsoncxx::v1::stdx::string_view key_alt_name); /// - /// Remove the specified data key. + /// Remove the given keyAltName from the specified data key. /// - /// @returns The data key before its removal. + /// @returns The data key before the removal of the given keyAltName. /// /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. /// @throws mongocxx::v1::exception for all other runtime errors. diff --git a/src/mongocxx/include/mongocxx/v1/client_session.hpp b/src/mongocxx/include/mongocxx/v1/client_session.hpp index 185ae34960..a2f2aa0fe2 100644 --- a/src/mongocxx/include/mongocxx/v1/client_session.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_session.hpp @@ -259,40 +259,8 @@ class client_session { MONGOCXX_ABI_EXPORT_CDECL(void) with_transaction(with_transaction_cb const& fn, v1::transaction const& opts); /// - /// Start and commit a new standalone transaction using `fn`. - /// - /// The default transaction options are applied to the new transaction. - /// - /// The behavior is approximately equivalent to: - /// ```cpp - /// this->start_transaction(); - /// while (/* unspecified */) { - /// try { - /// fn(); - /// this->commit_transaction(); // Success. - /// } catch (/* unspecified */) { - /// if (/* unspecified */) { - /// continue; // Retry attempt. - /// } else { - /// this->abort_transaction(); - /// throw; // Failure. - /// } - /// } - /// } - /// ``` - /// - /// Any user-defined exceptions thrown by `fn` will be caught and rethrown after the standalone transaction has been - /// aborted. - /// - /// @warning `fn` **MUST** allow any @ref mongocxx::v1::server_error exceptions thrown by an operation within `fn` - /// to propagate out of `fn` for correct retry attempt behavior. `fn` **MUST NOT** attempt to manually retry - /// operations. - /// - /// @note This operation uses an internal, non-configurable time limit of 120 seconds. The transaction may be - /// retried until this time limit is exceeded. - /// - /// @throws mongocxx::v1::exception when a client-side error is encountered. - /// @throws mongocxx::v1::server_error when a server-side error is encountered and all retry attempts have failed. + /// Equivalent to @ref with_transaction(with_transaction_cb const& fn, v1::transaction const& opts) with a + /// default-initialized @ref v1::transaction. /// MONGOCXX_ABI_EXPORT_CDECL(void) with_transaction(with_transaction_cb const& fn); }; diff --git a/src/mongocxx/include/mongocxx/v1/collection.hpp b/src/mongocxx/include/mongocxx/v1/collection.hpp index a88e24c89c..690bc93c51 100644 --- a/src/mongocxx/include/mongocxx/v1/collection.hpp +++ b/src/mongocxx/include/mongocxx/v1/collection.hpp @@ -562,7 +562,7 @@ class collection { /// /// Insert a single document into this collection as a bulk write operation. /// - /// If the document(s) do not contain an "_id" field, an "_id" field is generated using @ref bsoncxx::v1::oid. + /// If the document does not contain an "_id" field, an "_id" field is generated using @ref bsoncxx::v1::oid. /// /// @returns Empty when the bulk write operation is unacknowledged. /// @@ -782,7 +782,7 @@ class collection { /// /// - /// Update multiple documents in this collection as a bulk write operation. + /// Update a single document in this collection as a bulk write operation. /// /// @returns Empty when the bulk write operation is unacknowledged. /// diff --git a/src/mongocxx/include/mongocxx/v1/database.hpp b/src/mongocxx/include/mongocxx/v1/database.hpp index c876737cb0..d1493992b6 100644 --- a/src/mongocxx/include/mongocxx/v1/database.hpp +++ b/src/mongocxx/include/mongocxx/v1/database.hpp @@ -306,7 +306,7 @@ class database { /// Return a GridFS bucket for this database. /// /// @note When the "bucketName" field is unset, the default bucket name "fs" is used instead. - /// @note When the "chunkSizeBytes" field is unset, the default chunk size of 255 kB is used instead. + /// @note When the "chunkSizeBytes" field is unset, the default chunk size of 255 KiB is used instead. /// /// @see /// - [GridFS (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/gridfs/) diff --git a/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp b/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp index 56db91b53a..3d2df9b107 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp @@ -43,7 +43,7 @@ namespace v1 { /// - `hint` /// - `let` /// - `write_concern` ("writeConcern") -/// - comment` +/// - `comment` /// /// @see /// - [Delete Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/delete-methods/) diff --git a/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp b/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp index 2663b88ed5..e497eb7554 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp @@ -29,7 +29,7 @@ namespace mongocxx { namespace v1 { /// -/// The result of a "deleteOne" operation. +/// The result of a "deleteMany" operation. /// /// @see /// - [Delete Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/delete-methods/) diff --git a/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp b/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp index 54813c4a15..e7356db629 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp @@ -43,7 +43,7 @@ namespace v1 { /// - `hint` /// - `let` /// - `write_concern` ("writeConcern") -/// - comment` +/// - `comment` /// /// @see /// - [Delete Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/delete-methods/) diff --git a/src/mongocxx/include/mongocxx/v1/distinct_options.hpp b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp index 26964fad41..6db0dcedf9 100644 --- a/src/mongocxx/include/mongocxx/v1/distinct_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp @@ -106,12 +106,12 @@ class distinct_options { MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; /// - /// Set the "maxTime" field. + /// Set the "maxTimeMS" field. /// MONGOCXX_ABI_EXPORT_CDECL(distinct_options&) max_time(std::chrono::milliseconds max_time); /// - /// Return the current "maxTime" field. + /// Return the current "maxTimeMS" field. /// MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; diff --git a/src/mongocxx/include/mongocxx/v1/indexes.hpp b/src/mongocxx/include/mongocxx/v1/indexes.hpp index 4341aa4ab6..29901ced36 100644 --- a/src/mongocxx/include/mongocxx/v1/indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/indexes.hpp @@ -217,12 +217,12 @@ class indexes { MONGOCXX_ABI_EXPORT_CDECL() options(); /// - /// Set the "maxTime" field. + /// Set the "maxTimeMS" field. /// MONGOCXX_ABI_EXPORT_CDECL(options&) max_time(std::chrono::milliseconds max_time); /// - /// Return the current "maxTime" field. + /// Return the current "maxTimeMS" field. /// MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) max_time() const; @@ -481,7 +481,7 @@ class indexes { MONGOCXX_ABI_EXPORT_CDECL(v1::cursor) list(v1::client_session const& session); /// - /// Equivalent to `this->create_one(...)` with a single index model. + /// Equivalent to `this->create_one(model(keys, create_opts), opts)`. /// /// @param keys The "keys" field of the new index definition. /// @param create_opts "createIndexes" command options. @@ -495,7 +495,7 @@ class indexes { } /// - /// Equivalent to `this->create_one(...)` with a single index model. + /// Equivalent to `this->create_one(session, model(keys, create_opts), opts)`. /// /// @param session The session with which this operation is associated. /// @param keys The "keys" field of the new index definition. diff --git a/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp b/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp index 2a0142acc3..ce13f74812 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp @@ -82,8 +82,8 @@ class insert_many_result { /// MONGOCXX_ABI_EXPORT_CDECL(v1::bulk_write::result) result() const; - /// a - /// Return the number of inserted documents. + /// + /// Return the number of inserted documents. /// MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) inserted_count() const; diff --git a/src/mongocxx/include/mongocxx/v1/pool.hpp b/src/mongocxx/include/mongocxx/v1/pool.hpp index f8f1721d76..ad7eab4486 100644 --- a/src/mongocxx/include/mongocxx/v1/pool.hpp +++ b/src/mongocxx/include/mongocxx/v1/pool.hpp @@ -118,12 +118,11 @@ class pool { /// This function blocks the current thread until a client object is available or "waitQueueTimeoutMS" is /// triggered. /// - /// @note The first client object acquired from the pool blocks the current thread until the initial connection to - /// the MongoDB server(s) is established. + /// @note Connection to the MongoDB server(s) is attempted in a background "monitoring" thread when the first client + /// object is acquired. Server-side errors will only be encountered during or after the first command is executed. /// /// @returns A handle to a client object connected to the MongoDB server(s). /// - /// @throws mongocxx::v1::server_error when a server-side error is encountered and a raw server error is available. /// @throws mongocxx::v1::exception with @ref mongocxx::v1::pool::errc::wait_queue_timeout if a client object could /// not be acquired within "waitQueueTimeoutMS". /// @@ -135,12 +134,15 @@ class pool { /// @note The first client object acquired from a pool blocks the current thread until the initial connection to the /// MongoDB server(s) is established. /// + /// @note Connection to the MongoDB server(s) is attempted in a background "monitoring" thread when the first client + /// object is acquired. Server-side errors will only be encountered during or after the first command is executed. + /// /// @returns Empty when a client object is not immediately available. /// MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) try_acquire(); /// - /// Errors codes which may be returned by @ref mongocxx::v1::collection. + /// Errors codes which may be returned by @ref mongocxx::v1::pool. /// /// @attention This feature is experimental! It is not ready for use! /// @@ -150,7 +152,7 @@ class pool { }; /// - /// The error category for @ref mongocxx::v1::collection::errc. + /// The error category for @ref mongocxx::v1::pool::errc. /// /// @attention This feature is experimental! It is not ready for use! /// diff --git a/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp b/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp index 4791e897f6..3f79738082 100644 --- a/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp @@ -97,7 +97,7 @@ class replace_one_result { /// /// Return the upserted document ID. /// - /// @returns Empty when `this->modified_count() == 0`. + /// @returns Empty when no document was upserted. /// MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) upserted_id() const; diff --git a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp index d9d4fbc122..69387fa597 100644 --- a/src/mongocxx/include/mongocxx/v1/search_indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/search_indexes.hpp @@ -359,7 +359,7 @@ class search_indexes::model { model(bsoncxx::v1::stdx::string_view name, bsoncxx::v1::document::value definition); /// - /// Initialize this search index model with the given "name". + /// Initialize this search index model with the given "definition". /// /// @par Postconditions: /// - All other supported fields are "unset" or zero-initialized. diff --git a/src/mongocxx/include/mongocxx/v1/server_api.hpp b/src/mongocxx/include/mongocxx/v1/server_api.hpp index 602ec4b924..1b18a1d4bf 100644 --- a/src/mongocxx/include/mongocxx/v1/server_api.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_api.hpp @@ -101,7 +101,8 @@ class server_api { /// Initialize with the given server API version. /// /// @par Postconditions: - /// - All supported fields are "unset" or zero-initialized. + /// - `this->get_version() == v`. + /// - All other supported fields are "unset" or zero-initialized. /// explicit MONGOCXX_ABI_EXPORT_CDECL() server_api(version v); From 8e8c794b99bc59385569e2129cb4198732d3aa87 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 29 Oct 2025 12:44:49 -0500 Subject: [PATCH 27/33] Fix missing export macro --- src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp index 2b4df9b095..52e71bbfc4 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp @@ -116,7 +116,7 @@ class bucket { /// Equivalent to @ref open_upload_stream_with_id with a file ID generated using @ref bsoncxx::v1::oid. /// /// @{ - v1::gridfs::uploader open_upload_stream( + MONGOCXX_ABI_EXPORT_CDECL(v1::gridfs::uploader) open_upload_stream( bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const& opts = {}); From fab969264cbd9637ddd438cb3957003e2cb1ce21 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 29 Oct 2025 12:44:49 -0500 Subject: [PATCH 28/33] Support using sentinels in range-based overload templates --- .../include/mongocxx/v1/collection.hpp | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/collection.hpp b/src/mongocxx/include/mongocxx/v1/collection.hpp index 690bc93c51..b5d3f3dbde 100644 --- a/src/mongocxx/include/mongocxx/v1/collection.hpp +++ b/src/mongocxx/include/mongocxx/v1/collection.hpp @@ -105,6 +105,9 @@ class collection { template struct is_write_iter : bsoncxx::detail::is_detected {}; + template + struct is_sentinel_for : bsoncxx::detail::is_equality_comparable {}; + template struct is_container : bsoncxx::detail::conjunction, has_end> {}; @@ -252,14 +255,19 @@ class collection { /// @par Constraints: /// - `InputIt` satisfies Cpp17InputIterator. /// - The value type of `InputIt` is convertible to @ref mongocxx::v1::bulk_write::single. + /// - `Sentinel` satisfies `std::sentinel_for`. /// /// @see /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) /// /// @{ - template ::value>* = nullptr> + template < + typename InputIt, + typename Sentinel, + bsoncxx::detail::enable_if_t::value && is_sentinel_for::value>* = + nullptr> bsoncxx::v1::stdx::optional - bulk_write(InputIt begin, InputIt end, v1::bulk_write::options const& opts = {}) { + bulk_write(InputIt begin, Sentinel end, v1::bulk_write::options const& opts = {}) { v1::bulk_write bulk{this->create_bulk_write(opts)}; for (auto iter = begin; iter != end; ++iter) { bulk.append(*iter); @@ -267,11 +275,15 @@ class collection { return bulk.execute(); } - template ::value>* = nullptr> + template < + typename InputIt, + typename Sentinel, + bsoncxx::detail::enable_if_t::value && is_sentinel_for::value>* = + nullptr> bsoncxx::v1::stdx::optional bulk_write( v1::client_session const& session, InputIt begin, - InputIt end, + Sentinel end, v1::bulk_write::options const& opts = {}) { v1::bulk_write bulk{this->create_bulk_write(session, opts)}; for (auto iter = begin; iter != end; ++iter) { @@ -611,6 +623,7 @@ class collection { /// @par Constraints: /// - `InputIt` satisfies Cpp17InputIterator. /// - The value type of `InputIt` is convertible to @ref bsoncxx::v1::document::view. + /// - `Sentinel` satisfies `std::is_sentinel_for`. /// /// @returns Empty when the bulk write operation is unacknowledged. /// @@ -621,9 +634,13 @@ class collection { /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) /// /// @{ - template ::value>* = nullptr> + template < + typename InputIt, + typename Sentinel, + bsoncxx::detail::enable_if_t::value && is_sentinel_for::value>* = + nullptr> bsoncxx::v1::stdx::optional - insert_many(InputIt begin, InputIt end, v1::insert_many_options const& opts = {}) { + insert_many(InputIt begin, Sentinel end, v1::insert_many_options const& opts = {}) { v1::bulk_write bulk{this->_create_insert_many(nullptr, opts)}; std::vector inserted_ids; for (auto iter = begin; iter != end; ++iter) { @@ -632,11 +649,15 @@ class collection { return this->_execute_insert_many(bulk, inserted_ids); } - template ::value>* = nullptr> + template < + typename InputIt, + typename Sentinel, + bsoncxx::detail::enable_if_t::value && is_sentinel_for::value>* = + nullptr> bsoncxx::v1::stdx::optional insert_many( v1::client_session const& session, InputIt begin, - InputIt end, + Sentinel end, v1::insert_many_options const& opts = {}) { v1::bulk_write bulk{this->_create_insert_many(&session, opts)}; std::vector inserted_ids; From 19f72017b49f84b64e20bb62fb5d66db29f52623 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Wed, 29 Oct 2025 14:32:25 -0500 Subject: [PATCH 29/33] Avoid documenting internal representation details for bulk write results --- .../include/mongocxx/v1/bulk_write.hpp | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp index 6063e59dc8..466b9cc6dd 100644 --- a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp +++ b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp @@ -945,18 +945,14 @@ class bulk_write::options { /// The result of a write operation. /// /// Supported fields include: -/// - `inserted_count` ("nInserted" or "insertedCount") -/// - `matched_count` ("nMatched" or "matchedCount") -/// - `modified_count` ("nModified" or "modifiedCount") -/// - `deleted_count` ("nDeleted" or "deletedCount") -/// - `upserted_count` ("nUpserted" or "upsertedCount") -/// - `upserted_ids` ("upserted" or "upsertedIds") -/// -/// @important The raw server response is translated by mongoc into the Bulk Write API specification format even when -/// the CRUD API specification is used to implement the requested operations (see: `MONGOC_WRITE_RESULT_COMPLETE`). +/// - `inserted_count` ("insertedCount") +/// - `matched_count` ("matchedCount") +/// - `modified_count` ("modifiedCount") +/// - `deleted_count` ("deletedCount") +/// - `upserted_count` ("upsertedCount") +/// - `upserted_ids` ("upsertedIds") /// /// @see -/// - [`mongoc_bulk_operation_t` (mongoc)](https://mongoc.org/libmongoc/current/mongoc_bulk_operation_t.html) /// - [CRUD API (MongoDB Specifications)](https://specifications.readthedocs.io/en/latest/crud/crud/) /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) /// - [Update Methods (MongoDB Manual)](https://www.mongodb.com/docs/manual/reference/update-methods/) @@ -1011,27 +1007,27 @@ class bulk_write::result { MONGOCXX_ABI_EXPORT_CDECL() result(); /// - /// Return the value of the mongoc "nInserted" field. + /// Return the value of the "insertedCount" field. /// MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) inserted_count() const; /// - /// Return the value of the mongoc "nMatched" field. + /// Return the value of the "matchedCount" field. /// MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) matched_count() const; /// - /// Return the value of the mongoc "nModified" field. + /// Return the value of the "modifiedCount" field. /// MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) modified_count() const; /// - /// Return the value of the mongoc "nDeleted" field. + /// Return the value of the "deletedCount" field. /// MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) deleted_count() const; /// - /// Return the value of the mongoc "nUpserted" field. + /// Return the value of the "upsertedCount" field. /// MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) upserted_count() const; @@ -1041,9 +1037,9 @@ class bulk_write::result { using id_map = std::map; /// - /// Return a map from the operation index to the upserted document ID. + /// Return the "upsertedIds" field as a a map from the operation index to the upserted document ID. /// - /// @returns Empty when the "upserted" field is not present or is empty. + /// @returns Empty when the "upsertedIds" field is not present or is empty. /// MONGOCXX_ABI_EXPORT_CDECL(id_map) upserted_ids() const; From 5ade46e509c9bbce297ffcfca2c45baab22f88f5 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 30 Oct 2025 16:33:27 -0500 Subject: [PATCH 30/33] Move "errorLabels" support from v1::server_error to v1::exception --- src/mongocxx/include/mongocxx/v1/exception.hpp | 8 ++++++++ src/mongocxx/include/mongocxx/v1/server_error.hpp | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mongocxx/include/mongocxx/v1/exception.hpp b/src/mongocxx/include/mongocxx/v1/exception.hpp index 5a2e8845f7..50f69df99e 100644 --- a/src/mongocxx/include/mongocxx/v1/exception.hpp +++ b/src/mongocxx/include/mongocxx/v1/exception.hpp @@ -21,6 +21,7 @@ #include #include +#include #include @@ -102,6 +103,13 @@ class exception : public std::system_error { public: using std::system_error::system_error; + /// + /// Return true if this exception contains the specified error label. + /// + /// @important The set of error labels may vary depending on the operation and error. + /// + bool MONGOCXX_ABI_CDECL has_error_label(bsoncxx::v1::stdx::string_view label) const; + private: MONGOCXX_ABI_NO_EXPORT virtual void key_function() const; }; diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index 7945a8f406..c0ebb4eed0 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -23,7 +23,6 @@ #include #include -#include #include #include @@ -103,13 +102,6 @@ class server_error : public v1::exception { /// bsoncxx::v1::document::view MONGOCXX_ABI_CDECL raw() const; - /// - /// Return true if the raw server error contains the specified error label. - /// - /// @important The set of error labels may vary depending on the operation and error. - /// - bool MONGOCXX_ABI_CDECL has_error_label(bsoncxx::v1::stdx::string_view label) const; - private: void key_function() const override {} }; From ec483eadc1abfd9b3c10271e87105c02dff21447 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Thu, 30 Oct 2025 16:33:27 -0500 Subject: [PATCH 31/33] Make stateful exception classes nothrow copy constructible --- .../include/mongocxx/v1/exception.hpp | 12 +++++- .../include/mongocxx/v1/server_error.hpp | 40 +------------------ src/mongocxx/lib/CMakeLists.txt | 1 + src/mongocxx/lib/mongocxx/v1/exception.cpp | 13 +++++- src/mongocxx/lib/mongocxx/v1/exception.hh | 32 +++++++++++++++ src/mongocxx/lib/mongocxx/v1/instance.cpp | 5 ++- src/mongocxx/lib/mongocxx/v1/server_error.cpp | 2 +- 7 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 src/mongocxx/lib/mongocxx/v1/exception.hh diff --git a/src/mongocxx/include/mongocxx/v1/exception.hpp b/src/mongocxx/include/mongocxx/v1/exception.hpp index 50f69df99e..38f41f5aa2 100644 --- a/src/mongocxx/include/mongocxx/v1/exception.hpp +++ b/src/mongocxx/include/mongocxx/v1/exception.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -100,9 +101,11 @@ BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); /// @attention This feature is experimental! It is not ready for use! /// class exception : public std::system_error { - public: - using std::system_error::system_error; + private: + class impl; + std::shared_ptr _impl; + public: /// /// Return true if this exception contains the specified error label. /// @@ -110,7 +113,12 @@ class exception : public std::system_error { /// bool MONGOCXX_ABI_CDECL has_error_label(bsoncxx::v1::stdx::string_view label) const; + class internal; + private: + MONGOCXX_ABI_NO_EXPORT /* explicit(false) */ + exception(std::error_code ec, std::unique_ptr impl); + MONGOCXX_ABI_NO_EXPORT virtual void key_function() const; }; diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index c0ebb4eed0..d4068e86cc 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -49,45 +49,9 @@ BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); class server_error : public v1::exception { private: class impl; - std::unique_ptr _impl; + std::shared_ptr _impl; public: - /// - /// Destroy this object. - /// - /// @warning Invalidates all associated views. - /// - ~server_error() override; - - /// - /// Move constructor. - /// - /// @par Postconditions: - /// - `other` is in an assign-or-destroy-only state. - /// - MONGOCXX_ABI_CDECL server_error(server_error&& other) noexcept; - - /// - /// Move assignment. - /// - /// @par Postconditions: - /// - `other` is in an assign-or-destroy-only state. - /// - server_error& MONGOCXX_ABI_CDECL operator=(server_error&& other) noexcept; - - /// - /// Copy construction. - /// - MONGOCXX_ABI_CDECL server_error(server_error const& other); - - /// - /// Copy assignment. - /// - server_error& MONGOCXX_ABI_CDECL operator=(server_error const& other); - - // Inherit constructors. - using v1::exception::exception; - /// /// The client error code. /// @@ -103,7 +67,7 @@ class server_error : public v1::exception { bsoncxx::v1::document::view MONGOCXX_ABI_CDECL raw() const; private: - void key_function() const override {} + MONGOCXX_ABI_NO_EXPORT void key_function() const override; }; BSONCXX_PRIVATE_WARNINGS_POP(); diff --git a/src/mongocxx/lib/CMakeLists.txt b/src/mongocxx/lib/CMakeLists.txt index eb58a7308d..397f30f2fb 100644 --- a/src/mongocxx/lib/CMakeLists.txt +++ b/src/mongocxx/lib/CMakeLists.txt @@ -292,4 +292,5 @@ set_dist_list(src_mongocxx_lib_DIST mongocxx/v_noabi/mongocxx/write_concern.hh mongocxx/v1/config/config.hpp.in mongocxx/v1/config/version.hpp.in + mongocxx/v1/exception.hh ) diff --git a/src/mongocxx/lib/mongocxx/v1/exception.cpp b/src/mongocxx/lib/mongocxx/v1/exception.cpp index c76b4d1fb0..88e74d539d 100644 --- a/src/mongocxx/lib/mongocxx/v1/exception.cpp +++ b/src/mongocxx/lib/mongocxx/v1/exception.cpp @@ -12,14 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include // +#include #include #include +#include #include +#include #include namespace mongocxx { @@ -83,6 +86,10 @@ std::error_category const& type_error_category() { return instance.value(); } +class exception::impl {}; + +exception::exception(std::error_code ec, std::unique_ptr impl) : std::system_error{ec}, _impl{std::move(impl)} {} + // Prevent vague linkage of the vtable and type_info object (-Wweak-vtables). // - https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable // > The key function is the first non-pure virtual function that is not inline at the point of class definition. @@ -93,5 +100,9 @@ std::error_category const& type_error_category() { // vtable. void exception::key_function() const {} +exception exception::internal::make(std::error_code ec) { + return {ec, bsoncxx::make_unique()}; +} + } // namespace v1 } // namespace mongocxx diff --git a/src/mongocxx/lib/mongocxx/v1/exception.hh b/src/mongocxx/lib/mongocxx/v1/exception.hh new file mode 100644 index 0000000000..a71b5cba87 --- /dev/null +++ b/src/mongocxx/lib/mongocxx/v1/exception.hh @@ -0,0 +1,32 @@ +// Copyright 2009-present MongoDB, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include // IWYU pragma: export + +// + +#include + +#include + +namespace mongocxx { +namespace v1 { + +class exception::internal { + public: + static MONGOCXX_ABI_EXPORT_CDECL_TESTING(exception) make(std::error_code ec); +}; + +} // namespace v1 +} // namespace mongocxx diff --git a/src/mongocxx/lib/mongocxx/v1/instance.cpp b/src/mongocxx/lib/mongocxx/v1/instance.cpp index 3c6c147213..675ec3aaea 100644 --- a/src/mongocxx/lib/mongocxx/v1/instance.cpp +++ b/src/mongocxx/lib/mongocxx/v1/instance.cpp @@ -20,9 +20,10 @@ #include #include -#include #include +#include + #include #include #include @@ -99,7 +100,7 @@ class instance::impl { if (!instance_state.compare_exchange_strong( expected, 1, std::memory_order_acquire, std::memory_order_relaxed)) { - throw v1::exception{code::multiple_instances}; + throw v1::exception::internal::make(std::error_code{code::multiple_instances}); } } diff --git a/src/mongocxx/lib/mongocxx/v1/server_error.cpp b/src/mongocxx/lib/mongocxx/v1/server_error.cpp index ac466d5516..5c46f15610 100644 --- a/src/mongocxx/lib/mongocxx/v1/server_error.cpp +++ b/src/mongocxx/lib/mongocxx/v1/server_error.cpp @@ -19,7 +19,7 @@ namespace v1 { class server_error::impl {}; -server_error::~server_error() = default; +void server_error::key_function() const {} } // namespace v1 } // namespace mongocxx From 803d3a8934559b11f268ff3de1cf62a596216e21 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Fri, 31 Oct 2025 12:03:13 -0500 Subject: [PATCH 32/33] IWYU: make v1::exception transitively provided by v1::server_error --- src/mongocxx/include/mongocxx/v1/server_error.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/server_error.hpp b/src/mongocxx/include/mongocxx/v1/server_error.hpp index d4068e86cc..42ae965266 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -25,7 +25,7 @@ #include #include -#include +#include // IWYU pragma: export #include #include @@ -81,3 +81,6 @@ BSONCXX_PRIVATE_WARNINGS_POP(); /// @file /// Provides @ref mongocxx::v1::server_error. /// +/// @par Includes +/// - @ref mongocxx/v1/exception.hpp +/// From 6ec646534fadc629746782cba9e44b6a98c54de3 Mon Sep 17 00:00:00 2001 From: Ezra Chung Date: Fri, 31 Oct 2025 12:03:13 -0500 Subject: [PATCH 33/33] IWYU: make v1::client transitively provided by v1::pool --- src/mongocxx/include/mongocxx/v1/pool.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mongocxx/include/mongocxx/v1/pool.hpp b/src/mongocxx/include/mongocxx/v1/pool.hpp index ad7eab4486..7a2eb668b3 100644 --- a/src/mongocxx/include/mongocxx/v1/pool.hpp +++ b/src/mongocxx/include/mongocxx/v1/pool.hpp @@ -25,7 +25,7 @@ #include -#include +#include // IWYU pragma: export #include #include @@ -309,3 +309,6 @@ class pool::entry { /// @file /// Provides @ref mongocxx::v1::pool. /// +/// @par Includes +/// - @ref mongocxx/v1/client.hpp +///