diff --git a/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp b/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp index 8e3b5f5cf3..68742c91fe 100644 --- a/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/aggregate_options.hpp @@ -20,18 +20,204 @@ #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; + void* _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..cb9195b363 100644 --- a/src/mongocxx/include/mongocxx/v1/apm.hpp +++ b/src/mongocxx/include/mongocxx/v1/apm.hpp @@ -20,6 +20,25 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + namespace mongocxx { namespace v1 { @@ -31,7 +50,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; + void* _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_options.hpp b/src/mongocxx/include/mongocxx/v1/auto_encryption_options.hpp index 2e9d84d536..7c3333b5de 100644 --- a/src/mongocxx/include/mongocxx/v1/auto_encryption_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/auto_encryption_options.hpp @@ -20,17 +20,211 @@ #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_options {}; +class auto_encryption_options { + private: + class impl; + void* _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~auto_encryption_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() auto_encryption_options(auto_encryption_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption_options&) operator=(auto_encryption_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() auto_encryption_options(auto_encryption_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(auto_encryption_options&) operator=(auto_encryption_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() auto_encryption_options(); + + /// + /// 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_options&) 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_options&) 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_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(auto_encryption_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(auto_encryption_options&) 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_options&) 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_options&) 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_options&) 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_options&) 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_options&) 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..466b9cc6dd 100644 --- a/src/mongocxx/include/mongocxx/v1/bulk_write.hpp +++ b/src/mongocxx/include/mongocxx/v1/bulk_write.hpp @@ -16,6 +16,30 @@ #include +// + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -33,105 +57,1010 @@ 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: /// - /// A single "Insert One" write operation. + /// The document to be inserted. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + bsoncxx::v1::document::value value; + /// - /// @attention This feature is experimental! It is not ready for use! + /// Initialize with `doc`. /// - class insert_one {}; + /* explicit(false) */ insert_one(bsoncxx::v1::document::value doc) : value{std::move(doc)} {} /// - /// A single "Update One" write operation. + /// Equivalent to `this->value`. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + 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; + void* _impl; + + public: + /// + /// Destroy this object. /// - /// @attention This feature is experimental! It is not ready for use! + /// @warning Invalidates all associated views. /// - class update_one {}; + MONGOCXX_ABI_EXPORT_CDECL() ~update_one(); /// - /// A single "Update Many" write operation. + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() update_one(update_one&& 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 update_many {}; + MONGOCXX_ABI_EXPORT_CDECL(update_one&) operator=(update_one&& other) noexcept; /// - /// A single "Replace One" write operation. + /// Copy construction. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + MONGOCXX_ABI_EXPORT_CDECL() update_one(update_one const& other); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Copy assignment. /// - class replace_one {}; + MONGOCXX_ABI_EXPORT_CDECL(update_one&) operator=(update_one const& other); /// - /// A single "Delete One" write operation. + /// Initialize with the given "filter" and "update" documents. /// - /// @see - /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// @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); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Initialize with the given "filter" document and "update" aggregation pipeline. /// - class delete_one {}; + /// @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); /// - /// A single "Delete 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; + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "update" field. /// - class delete_many {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) update() const; /// - /// A single 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(update_one&) collation(bsoncxx::v1::document::value v); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "collation" field. /// - class single {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) collation() const; /// - /// Options for 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(update_one&) hint(v1::hint v); + /// - /// @attention This feature is experimental! It is not ready for use! + /// Return the current "hint" field. /// - class options {}; + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) hint() const; /// - /// The result of a write operation. + /// Set the "sort" 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(update_one&) sort(bsoncxx::v1::document::value v); + + /// + /// Return the current "sort" field. /// - /// @attention This feature is experimental! It is not ready for use! + 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; + void* _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; + void* _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; + void* _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~delete_one(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_one(delete_one&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one&) operator=(delete_one&& other) noexcept; + + /// + /// 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); + + /// + /// Return the current "filter" field. + /// + 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; + + /// + /// Set the "hint" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_one&) hint(v1::hint v); + + /// + /// Return the current "hint" field. + /// + 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; + void* _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~delete_many(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many(delete_many&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many&) operator=(delete_many&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() delete_many(delete_many const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_many&) operator=(delete_many const& other); + + /// + /// Initialize with the given "filter". + /// + /// @par Postconditions: + /// - All other supported fields are "unset" or zero-initialized. + /// + explicit MONGOCXX_ABI_EXPORT_CDECL() delete_many(bsoncxx::v1::document::value filter); + + /// + /// Return the current "filter" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) filter() const; + + /// + /// Set the "collation" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(delete_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(delete_many&) hint(v1::hint v); + + /// + /// 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; + void* _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; + void* _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` ("insertedCount") +/// - `matched_count` ("matchedCount") +/// - `modified_count` ("modifiedCount") +/// - `deleted_count` ("deletedCount") +/// - `upserted_count` ("upsertedCount") +/// - `upserted_ids` ("upsertedIds") +/// +/// @see +/// - [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/) +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class bulk_write::result { + private: + class impl; + void* _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 "insertedCount" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) inserted_count() const; + + /// + /// Return the value of the "matchedCount" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) matched_count() const; + + /// + /// Return the value of the "modifiedCount" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) modified_count() const; + + /// + /// Return the value of the "deletedCount" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(std::int64_t) deleted_count() const; + + /// + /// Return the value of the "upsertedCount" 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 the "upsertedIds" field as a a map from the operation index to the upserted document ID. + /// + /// @returns Empty when the "upsertedIds" field is not present or is empty. + /// + MONGOCXX_ABI_EXPORT_CDECL(id_map) upserted_ids() const; + + /// + /// Compare equal when all supported fields 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..3ce888478c 100644 --- a/src/mongocxx/include/mongocxx/v1/change_stream.hpp +++ b/src/mongocxx/include/mongocxx/v1/change_stream.hpp @@ -20,24 +20,400 @@ #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; + void* _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; + void* _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: + void* _impl; // v1::change_stream + + 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..7391662d6f 100644 --- a/src/mongocxx/include/mongocxx/v1/client.hpp +++ b/src/mongocxx/include/mongocxx/v1/client.hpp @@ -20,6 +20,26 @@ #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -35,12 +55,304 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class client { + private: + class impl; + void* _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. + /// + /// @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::exception when a client-side error is encountered. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL() client(v1::uri uri, options const& opts); + + /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() client(v1::uri uri); + /// @} + /// + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - `*this` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() client(); + + /// + /// Return true when `*this` is NOT in an assign-or-destroy-only state. /// - /// Options for @ref mongocxx::v1::client. + explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const; + + /// + /// Return the @ref mongocxx::v1::uri 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(); + /// @} + /// + + /// + /// 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; + void* _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_options 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..38c1607dee 100644 --- a/src/mongocxx/include/mongocxx/v1/client_encryption.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_encryption.hpp @@ -20,6 +20,29 @@ #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 +52,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 +60,330 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class client_encryption { + private: + void* _impl; // mongoc_client_encryption_t + + 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_options 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 "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. + /// @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 "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. + /// + /// @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_options 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_options 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 given keyAltName from the specified data key. + /// + /// @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. + /// + 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; + void* _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(mongocxx::v1::client*) 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..a2f2aa0fe2 100644 --- a/src/mongocxx/include/mongocxx/v1/client_session.hpp +++ b/src/mongocxx/include/mongocxx/v1/client_session.hpp @@ -20,6 +20,19 @@ #include +#include +#include + +#include +#include + +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -33,12 +46,310 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class client_session { + private: + class impl; + void* _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); + + /// + /// 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); +}; + +/// +/// 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: + void* _impl; // mongoc_session_opt_t + + 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..b5d3f3dbde 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,55 @@ #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 +#include +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -31,11 +80,876 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class collection {}; +class collection { + private: + class impl; + void* _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_sentinel_for : bsoncxx::detail::is_equality_comparable {}; + + 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. + /// - `Sentinel` satisfies `std::sentinel_for`. + /// + /// @see + /// - [Bulk Write Operations (MongoDB Manual)](https://www.mongodb.com/docs/manual/core/bulk-write-operations/) + /// + /// @{ + template < + typename InputIt, + typename Sentinel, + bsoncxx::detail::enable_if_t::value && is_sentinel_for::value>* = + nullptr> + bsoncxx::v1::stdx::optional + 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); + } + return bulk.execute(); + } + + 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, + 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) { + 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 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. + /// + /// @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. + /// - `Sentinel` satisfies `std::is_sentinel_for`. + /// + /// @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 < + typename InputIt, + typename Sentinel, + bsoncxx::detail::enable_if_t::value && is_sentinel_for::value>* = + nullptr> + bsoncxx::v1::stdx::optional + 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) { + this->_append_insert_many(bulk, inserted_ids, *iter); + } + return this->_execute_insert_many(bulk, inserted_ids); + } + + 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, + Sentinel 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 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) 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..d6bdf501e9 100644 --- a/src/mongocxx/include/mongocxx/v1/count_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/count_options.hpp @@ -20,18 +20,158 @@ #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; + void* _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..02147bebca 100644 --- a/src/mongocxx/include/mongocxx/v1/cursor.hpp +++ b/src/mongocxx/include/mongocxx/v1/cursor.hpp @@ -20,6 +20,13 @@ #include +#include + +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +38,229 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class cursor {}; +class cursor { + private: + class impl; + void* _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: + void* _impl; // v1::cursor + + 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_options.hpp b/src/mongocxx/include/mongocxx/v1/data_key_options.hpp index 2db89d5fb4..0fd2f9e508 100644 --- a/src/mongocxx/include/mongocxx/v1/data_key_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/data_key_options.hpp @@ -20,18 +20,115 @@ #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_options {}; +class data_key_options { + private: + class impl; + void* _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~data_key_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() data_key_options(data_key_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key_options&) operator=(data_key_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() data_key_options(data_key_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key_options&) operator=(data_key_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() data_key_options(); + + /// + /// Set the "masterKey" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key_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; + + /// + /// Set the "keyAltNames" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(data_key_options&) 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_options&) 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..d1493992b6 100644 --- a/src/mongocxx/include/mongocxx/v1/database.hpp +++ b/src/mongocxx/include/mongocxx/v1/database.hpp @@ -20,6 +20,29 @@ #include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +54,296 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class database {}; +class database { + private: + class impl; + void* _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 KiB 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& 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 = {}); + /// @} + /// +}; } // 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..3d2df9b107 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_options.hpp @@ -20,18 +20,133 @@ #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; + void* _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..e497eb7554 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_many_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_many_result {}; +class delete_many_result { + private: + class impl; + void* _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..e7356db629 100644 --- a/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/delete_one_options.hpp @@ -20,18 +20,133 @@ #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; + void* _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..320f12a1dc 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; + void* _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/distinct_options.hpp b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp index ea9da71e30..6db0dcedf9 100644 --- a/src/mongocxx/include/mongocxx/v1/distinct_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/distinct_options.hpp @@ -20,16 +20,121 @@ #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; + void* _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 "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(distinct_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(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_options.hpp b/src/mongocxx/include/mongocxx/v1/encrypt_options.hpp index e61266c133..99cc79e3ea 100644 --- a/src/mongocxx/include/mongocxx/v1/encrypt_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/encrypt_options.hpp @@ -20,12 +20,33 @@ #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 +57,139 @@ namespace v1 { class encrypt_options { // This class implements `EncryptOpts`: // - https://specifications.readthedocs.io/en/latest/client-side-encryption/client-side-encryption/ + + private: + class impl; + void* _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_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() encrypt_options(encrypt_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt_options&) operator=(encrypt_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() encrypt_options(encrypt_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt_options&) operator=(encrypt_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() encrypt_options(); + + /// + /// Set the "keyId" field. + /// + /// @param v A @ref bsoncxx::v1::types::binary_subtype::k_uuid. + /// + MONGOCXX_ABI_EXPORT_CDECL(encrypt_options&) 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_options&) 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_options&) 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_options&) 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_options&) 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_options&) range_opts(v1::range_options 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..f4af9ebf63 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,111 @@ #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; + void* _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..76c3803753 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_failed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_failed.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_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..42cc128b13 100644 --- a/src/mongocxx/include/mongocxx/v1/events/command_started.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/command_started.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_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 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_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..e3e3a31840 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..3d6576cc6d 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_closed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_closed.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 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..92b9929ac3 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,90 @@ namespace events { /// /// @attention This feature is experimental! It is not ready for use! /// -class server_description {}; +class server_description { + private: + void* _impl; // mongoc_server_description_t + + 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(bsoncxx::v1::stdx::optional) 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..bfb14b5da8 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,16 @@ #include +#include + +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +42,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..6d881551d7 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,42 @@ 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 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; + + 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..a65d72929b 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,12 @@ #include +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +38,32 @@ 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 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; + + 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..847a218732 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,14 @@ #include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +40,42 @@ 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 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; + + 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..4ca4fecc53 100644 --- a/src/mongocxx/include/mongocxx/v1/events/server_opening.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/server_opening.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 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 +70,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..b5c135bb76 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_closed.hpp @@ -20,6 +20,12 @@ #include +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +38,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..deeb062f28 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_description.hpp @@ -20,6 +20,15 @@ #include +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +41,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..db9822205e 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,12 @@ #include +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +38,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..435f7dcaf1 100644 --- a/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp +++ b/src/mongocxx/include/mongocxx/v1/events/topology_opening.hpp @@ -20,6 +20,12 @@ #include +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace events { @@ -32,7 +38,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/exception.hpp b/src/mongocxx/include/mongocxx/v1/exception.hpp index 5a2e8845f7..38f41f5aa2 100644 --- a/src/mongocxx/include/mongocxx/v1/exception.hpp +++ b/src/mongocxx/include/mongocxx/v1/exception.hpp @@ -21,9 +21,11 @@ #include #include +#include #include +#include #include #include @@ -99,10 +101,24 @@ BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); /// @attention This feature is experimental! It is not ready for use! /// class exception : public std::system_error { + private: + class impl; + std::shared_ptr _impl; + 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; + + 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/find_one_and_delete_options.hpp b/src/mongocxx/include/mongocxx/v1/find_one_and_delete_options.hpp index cb2c8a27e7..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 @@ -20,19 +20,169 @@ #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; + void* _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..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 @@ -20,19 +20,204 @@ #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; + void* _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..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 @@ -20,19 +20,216 @@ #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; + void* _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..017a2b5d00 100644 --- a/src/mongocxx/include/mongocxx/v1/find_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/find_options.hpp @@ -20,18 +20,302 @@ #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; + void* _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..52e71bbfc4 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/bucket.hpp @@ -20,6 +20,32 @@ #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 +58,380 @@ namespace gridfs { /// /// @attention This feature is experimental! It is not ready for use! /// -class bucket {}; +class bucket { + private: + class impl; + void* _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. + /// + /// @{ + MONGOCXX_ABI_EXPORT_CDECL(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. + /// + /// @{ + 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& output); + /// @} + /// + + /// + /// 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; + void* _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..81e17f9d4f 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/downloader.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -32,12 +41,138 @@ namespace gridfs { /// /// @attention This feature is experimental! It is not ready for use! /// -class downloader {}; +class downloader { + private: + class impl; + void* _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..a4b0119e6d 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/upload_options.hpp @@ -20,6 +20,15 @@ #include +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -27,12 +36,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; + void* _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..1c8e233af9 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/upload_result.hpp @@ -20,6 +20,10 @@ #include +#include + +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -27,12 +31,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; + void* _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..8270636bfb 100644 --- a/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp +++ b/src/mongocxx/include/mongocxx/v1/gridfs/uploader.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include +#include +#include +#include + namespace mongocxx { namespace v1 { namespace gridfs { @@ -32,12 +41,174 @@ namespace gridfs { /// /// @attention This feature is experimental! It is not ready for use! /// -class uploader {}; +class uploader { + private: + class impl; + void* _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..761061cbf3 100644 --- a/src/mongocxx/include/mongocxx/v1/hint.hpp +++ b/src/mongocxx/include/mongocxx/v1/hint.hpp @@ -20,6 +20,17 @@ #include +#include +#include + +#include +#include +#include + +#include + +#include + namespace mongocxx { namespace v1 { @@ -29,11 +40,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; + void* _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..29901ced36 100644 --- a/src/mongocxx/include/mongocxx/v1/indexes.hpp +++ b/src/mongocxx/include/mongocxx/v1/indexes.hpp @@ -20,6 +20,25 @@ #include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -37,10 +56,18 @@ class indexes { // This class implements `IndexView` ("Index View API"): // - https://specifications.readthedocs.io/en/latest/index-management/index-management/ + private: + class impl; + void* _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 +76,643 @@ class indexes { class model { // This class implements `IndexModel` ("Index View API"): // - https://specifications.readthedocs.io/en/latest/index-management/index-management/ + + private: + class impl; + void* _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` + /// - `version` ("v") + /// - `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; + void* _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 "maxTimeMS" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(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 "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. + /// + indexes& 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(model(keys, create_opts), opts)`. + /// + /// @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(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. + /// @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..2d8f4b8443 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_many_options.hpp @@ -20,18 +20,119 @@ #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; + void* _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..ce13f74812 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_many_result.hpp @@ -20,6 +20,13 @@ #include +#include + +#include +#include + +#include + namespace mongocxx { namespace v1 { @@ -31,7 +38,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; + void* _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; + + /// + /// 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..0545f4bd0d 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_one_options.hpp @@ -20,18 +20,108 @@ #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; + void* _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..b3198f5cce 100644 --- a/src/mongocxx/include/mongocxx/v1/insert_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/insert_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 insert_one_result {}; +class insert_one_result { + private: + class impl; + void* _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..77ae225cd5 100644 --- a/src/mongocxx/include/mongocxx/v1/pipeline.hpp +++ b/src/mongocxx/include/mongocxx/v1/pipeline.hpp @@ -20,6 +20,15 @@ #include +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { @@ -31,7 +40,219 @@ namespace v1 { /// /// @attention This feature is experimental! It is not ready for use! /// -class pipeline {}; +class pipeline { + private: + class impl; + void* _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..7a2eb668b3 100644 --- a/src/mongocxx/include/mongocxx/v1/pool.hpp +++ b/src/mongocxx/include/mongocxx/v1/pool.hpp @@ -20,6 +20,18 @@ #include +#include +#include + +#include + +#include // IWYU pragma: export +#include + +#include +#include +#include + namespace mongocxx { namespace v1 { @@ -36,12 +48,256 @@ namespace v1 { /// @attention This feature is experimental! It is not ready for use! /// class pool { + private: + class impl; + void* _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 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::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. + /// + /// @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::pool. /// /// @attention This feature is experimental! It is not ready for use! /// - class options {}; + enum class errc { + zero, ///< Zero. + wait_queue_timeout, ///< Failed to acquire a client object due to "waitQueueTimeoutMS". + }; + + /// + /// The error category for @ref mongocxx::v1::pool::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::pool. +/// +/// @attention This feature is experimental! It is not ready for use! +/// +class pool::options { + private: + class impl; + void* _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; + void* _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 @@ -53,3 +309,6 @@ class pool { /// @file /// Provides @ref mongocxx::v1::pool. /// +/// @par Includes +/// - @ref mongocxx/v1/client.hpp +/// diff --git a/src/mongocxx/include/mongocxx/v1/range_options.hpp b/src/mongocxx/include/mongocxx/v1/range_options.hpp index a3ac2ce760..4ec65d5f89 100644 --- a/src/mongocxx/include/mongocxx/v1/range_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/range_options.hpp @@ -20,18 +20,136 @@ #include +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// -/// Options related to range queries for Queryable Encryption. +/// Options related to range_options 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_options {}; +class range_options { + private: + class impl; + void* _impl; + + public: + /// + /// Destroy this object. + /// + /// @warning Invalidates all associated views. + /// + MONGOCXX_ABI_EXPORT_CDECL() ~range_options(); + + /// + /// Move constructor. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL() range_options(range_options&& other) noexcept; + + /// + /// Move assignment. + /// + /// @par Postconditions: + /// - `other` is in an assign-or-destroy-only state. + /// + MONGOCXX_ABI_EXPORT_CDECL(range_options&) operator=(range_options&& other) noexcept; + + /// + /// Copy construction. + /// + MONGOCXX_ABI_EXPORT_CDECL() range_options(range_options const& other); + + /// + /// Copy assignment. + /// + MONGOCXX_ABI_EXPORT_CDECL(range_options&) operator=(range_options const& other); + + /// + /// Default initialization. + /// + /// @par Postconditions: + /// - All supported fields are "unset" or zero-initialized. + /// + MONGOCXX_ABI_EXPORT_CDECL() range_options(); + + /// + /// Set the "min" field. + /// + MONGOCXX_ABI_EXPORT_CDECL(range_options&) 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_options&) 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_options&) 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_options&) 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_options&) 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..4689f494d7 100644 --- a/src/mongocxx/include/mongocxx/v1/read_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_concern.hpp @@ -20,18 +20,177 @@ #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: + void* _impl; // mongoc_read_concern_t + + 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 level::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 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); + + /// + /// 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` is empty. + /// + MONGOCXX_ABI_EXPORT_CDECL(read_concern&) acknowledge_string(bsoncxx::v1::stdx::string_view v); + + /// + /// Return the current read concern level as a string. + /// + /// @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; + + /// + /// 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..bf2d5933f8 100644 --- a/src/mongocxx/include/mongocxx/v1/read_preference.hpp +++ b/src/mongocxx/include/mongocxx/v1/read_preference.hpp @@ -20,18 +20,187 @@ #include +#include +#include + +#include + +#include + +#include + namespace mongocxx { namespace v1 { /// /// Options related to a MongoDB Read Preference. /// +/// Supported fields include: +/// - `hedge` +/// - `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: + void* _impl; // mongoc_read_prefs_t + + 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: + /// - 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. + /// + /// @param v One of: + /// - @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/) + /// + 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..484813469f 100644 --- a/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/replace_one_options.hpp @@ -20,18 +20,166 @@ #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; + void* _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..3f79738082 100644 --- a/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/replace_one_result.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include +#include + +#include + namespace mongocxx { namespace v1 { @@ -31,7 +40,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; + void* _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 no document was upserted. + /// + 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..2833891285 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; + void* _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..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,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; + void* _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..69387fa597 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; + void* _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; + void* _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 "definition". + /// + /// @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..1b18a1d4bf 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 + 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; + void* _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: + /// - `this->get_version() == v`. + /// - All other 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..42ae965266 100644 --- a/src/mongocxx/include/mongocxx/v1/server_error.hpp +++ b/src/mongocxx/include/mongocxx/v1/server_error.hpp @@ -18,29 +18,69 @@ // -#include +#include + +#include + +#include + +#include +#include // IWYU pragma: export + +#include #include namespace mongocxx { namespace v1 { +BSONCXX_PRIVATE_WARNINGS_PUSH(); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251)); +BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); + /// /// 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::shared_ptr _impl; + + public: + /// + /// 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; + + private: + MONGOCXX_ABI_NO_EXPORT void key_function() const override; +}; + +BSONCXX_PRIVATE_WARNINGS_POP(); } // namespace v1 } // namespace mongocxx +#include + /// /// @file /// Provides @ref mongocxx::v1::server_error. /// +/// @par Includes +/// - @ref mongocxx/v1/exception.hpp +/// diff --git a/src/mongocxx/include/mongocxx/v1/tls.hpp b/src/mongocxx/include/mongocxx/v1/tls.hpp index 1162f9a266..cb0a343f79 100644 --- a/src/mongocxx/include/mongocxx/v1/tls.hpp +++ b/src/mongocxx/include/mongocxx/v1/tls.hpp @@ -20,16 +20,138 @@ #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; + void* _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..0f6a5f87ad 100644 --- a/src/mongocxx/include/mongocxx/v1/transaction.hpp +++ b/src/mongocxx/include/mongocxx/v1/transaction.hpp @@ -20,18 +20,119 @@ #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: + void* _impl; // mongoc_transaction_opt_t + + 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..70ed13788f 100644 --- a/src/mongocxx/include/mongocxx/v1/update_many_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_many_options.hpp @@ -20,18 +20,179 @@ #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; + void* _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..d79e8e06d6 100644 --- a/src/mongocxx/include/mongocxx/v1/update_many_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_many_result.hpp @@ -20,6 +20,16 @@ #include +#include + +#include + +#include +#include + +#include +#include + namespace mongocxx { namespace v1 { @@ -31,7 +41,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; + void* _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..5ebaec0ca9 100644 --- a/src/mongocxx/include/mongocxx/v1/update_one_options.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_one_options.hpp @@ -20,18 +20,179 @@ #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; + void* _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..3c2c27da10 100644 --- a/src/mongocxx/include/mongocxx/v1/update_one_result.hpp +++ b/src/mongocxx/include/mongocxx/v1/update_one_result.hpp @@ -20,6 +20,15 @@ #include +#include + +#include + +#include +#include + +#include + namespace mongocxx { namespace v1 { @@ -31,7 +40,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; + void* _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..7bfeba2853 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,371 @@ #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: + void* _impl; // mongoc_uri_t + + 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(bsoncxx::v1::stdx::string_view v); + + /// + /// Return the "authMechanism" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) auth_mechanism() const; + + /// + /// Return the "authSource" option. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::string_view) 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(bsoncxx::v1::stdx::string_view) 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(bsoncxx::v1::stdx::string_view) 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(bsoncxx::v1::stdx::string_view) 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(bsoncxx::v1::stdx::string_view) 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..5bc0fabcf9 100644 --- a/src/mongocxx/include/mongocxx/v1/write_concern.hpp +++ b/src/mongocxx/include/mongocxx/v1/write_concern.hpp @@ -20,18 +20,235 @@ #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: + void* _impl; // mongoc_write_concern_t + + 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 level::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 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; + + /// + /// 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 level::k_unacknowledged or @ref + /// level::k_acknowledged. + /// + MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional) nodes() const; + + /// + /// Set the "w" field to a custom write concern name. + /// + MONGOCXX_ABI_EXPORT_CDECL(write_concern&) tag(bsoncxx::v1::stdx::string_view v); + + /// + /// Return the current "w" value as a custom write concern name. + /// + /// @returns Empty when `this->acknowledge_level()` is not @ref level::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/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 4e03449e62..5c46f15610 100644 --- a/src/mongocxx/lib/mongocxx/v1/server_error.cpp +++ b/src/mongocxx/lib/mongocxx/v1/server_error.cpp @@ -13,3 +13,13 @@ // limitations under the License. #include + +namespace mongocxx { +namespace v1 { + +class server_error::impl {}; + +void server_error::key_function() const {} + +} // namespace v1 +} // namespace mongocxx