|
MongoDB C++ Driver
mongocxx-3.0.2
|
Class representing server side document groupings within a MongoDB database. More...
#include <collection.hpp>
Public Member Functions | |
| collection () noexcept | |
| Default constructs a collection object. More... | |
| collection (collection &&) noexcept | |
| Move constructs a collection. | |
| collection & | operator= (collection &&) noexcept |
| Move assigns a collection. | |
| collection (const collection &) | |
| Copy constructs a collection. | |
| collection & | operator= (const collection &) |
| Copy assigns a collection. | |
| ~collection () | |
| Destroys a collection. | |
| operator bool () const noexcept | |
| Returns true if the collection is valid, meaning it was not default constructed or moved from. | |
| cursor | aggregate (const pipeline &pipeline, const options::aggregate &options=options::aggregate()) |
| Runs an aggregation framework pipeline against this collection. More... | |
| template<typename container_type > | |
| stdx::optional< result::bulk_write > | bulk_write (const container_type &writes, const options::bulk_write &options=options::bulk_write()) |
| Sends a container of writes to the server as a bulk write operation. More... | |
| template<typename write_model_iterator_type > | |
| stdx::optional< result::bulk_write > | bulk_write (write_model_iterator_type begin, write_model_iterator_type end, const options::bulk_write &options=options::bulk_write()) |
Sends writes starting at begin and ending at end to the server as a bulk write operation. More... | |
| stdx::optional< result::bulk_write > | bulk_write (const class bulk_write &bulk_write) |
| Sends a batch of writes represented by the bulk_write to the server. More... | |
| std::int64_t | count (bsoncxx::document::view_or_value filter, const options::count &options=options::count()) |
| Counts the number of documents matching the provided filter. More... | |
| bsoncxx::document::value | create_index (bsoncxx::document::view_or_value keys, const options::index &options=options::index()) |
| Creates an index over the collection for the provided keys with the provided options. More... | |
| stdx::optional< result::delete_result > | delete_many (bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options()) |
| Deletes all matching documents from the collection. More... | |
| stdx::optional< result::delete_result > | delete_one (bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options()) |
| Deletes a single matching document from the collection. More... | |
| cursor | distinct (bsoncxx::string::view_or_value name, bsoncxx::document::view_or_value filter, const options::distinct &options=options::distinct()) |
| Finds the distinct values for a specified field accross the collection. More... | |
| void | drop () |
| Drops this collection and all its contained documents from the database. More... | |
| cursor | find (bsoncxx::document::view_or_value filter, const options::find &options=options::find()) |
| Finds the documents in this collection which match the provided filter. More... | |
| stdx::optional< bsoncxx::document::value > | find_one (bsoncxx::document::view_or_value filter, const options::find &options=options::find()) |
| Finds a single document in this collection that match the provided filter. More... | |
| stdx::optional< bsoncxx::document::value > | find_one_and_delete (bsoncxx::document::view_or_value filter, const options::find_one_and_delete &options=options::find_one_and_delete()) |
| Finds a single document matching the filter, deletes it, and returns the original. More... | |
| stdx::optional< bsoncxx::document::value > | find_one_and_replace (bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::find_one_and_replace &options=options::find_one_and_replace()) |
| Finds a single document matching the filter, replaces it, and returns either the original or the replacement document. More... | |
| stdx::optional< bsoncxx::document::value > | find_one_and_update (bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::find_one_and_update &options=options::find_one_and_update()) |
| Finds a single document matching the filter, updates it, and returns either the original or the newly-updated document. More... | |
| stdx::optional< result::insert_one > | insert_one (bsoncxx::document::view_or_value document, const options::insert &options=options::insert()) |
| Inserts a single document into the collection. More... | |
| template<typename container_type > | |
| stdx::optional< result::insert_many > | insert_many (const container_type &container, const options::insert &options=options::insert()) |
| Inserts multiple documents into the collection. More... | |
| template<typename document_view_iterator_type > | |
| stdx::optional< result::insert_many > | insert_many (document_view_iterator_type begin, document_view_iterator_type end, const options::insert &options=options::insert()) |
| Inserts multiple documents into the collection. More... | |
| cursor | list_indexes () const |
| Returns a list of the indexes currently on this collection. More... | |
| stdx::string_view | name () const |
| Returns the name of this collection as a view of a null-terminated string. More... | |
| void | rename (bsoncxx::string::view_or_value new_name, bool drop_target_before_rename=false) |
| Rename this collection. More... | |
| void | read_concern (class read_concern rc) |
| Sets the read_concern for this collection. More... | |
| class read_concern | read_concern () const |
| Gets the read_concern for the collection. More... | |
| void | read_preference (class read_preference rp) |
| Sets the read_preference for this collection. More... | |
| class read_preference | read_preference () const |
| Gets the read_preference for the collection. More... | |
| stdx::optional< result::replace_one > | replace_one (bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::update &options=options::update()) |
| Replaces a single document matching the provided filter in this collection. More... | |
| stdx::optional< result::update > | update_many (bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::update &options=options::update()) |
| Updates multiple documents matching the provided filter in this collection. More... | |
| stdx::optional< result::update > | update_one (bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::update &options=options::update()) |
| Updates a single document matching the provided filter in this collection. More... | |
| void | write_concern (class write_concern wc) |
| Sets the write_concern for this collection. More... | |
| class write_concern | write_concern () const |
| Gets the write_concern for the collection. More... | |
Class representing server side document groupings within a MongoDB database.
Collections do not require or enforce a schema and documents inside of a collection can have different fields. While not a requirement, typically documents in a collection have a similar shape or related purpose.
Example:
|
noexcept |
Default constructs a collection object.
The collection is equivalent to the state of a moved from colletion. The only valid actions to take with a default constructed collection are to assign to it, or destroy it.
| cursor mongocxx::collection::aggregate | ( | const pipeline & | pipeline, |
| const options::aggregate & | options = options::aggregate() |
||
| ) |
Runs an aggregation framework pipeline against this collection.
| pipeline | The pipeline of aggregation operations to perform. |
| options | Optional arguments, see mongocxx::options::aggregate. |
| stdx::optional< result::bulk_write > mongocxx::collection::bulk_write | ( | const container_type & | writes, |
| const options::bulk_write & | options = options::bulk_write() |
||
| ) |
Sends a container of writes to the server as a bulk write operation.
| containter_type | The container type. Must meet the requirements for the container concept with a value type of model::write. |
| writes | A container of model::write. |
| options | Optional arguments, see options::bulk_write. |
| mongocxx::bulk_write_exception | when there are errors processing the writes. |
| stdx::optional< result::bulk_write > mongocxx::collection::bulk_write | ( | write_model_iterator_type | begin, |
| write_model_iterator_type | end, | ||
| const options::bulk_write & | options = options::bulk_write() |
||
| ) |
Sends writes starting at begin and ending at end to the server as a bulk write operation.
| write_model_iterator_type | The container type. Must meet the requirements for the input iterator concept with a value type of model::write. |
| begin | Iterator pointing to the first model::write to send. |
| end | Iterator pointing to the end of the writes to send. |
| options | Optional arguments, see options::bulk_write. |
| mongocxx::bulk_write_exception | when there are errors processing the writes. |
| stdx::optional<result::bulk_write> mongocxx::collection::bulk_write | ( | const class bulk_write & | bulk_write | ) |
Sends a batch of writes represented by the bulk_write to the server.
| bulk_write | A bulk write which contains multiple write operations. |
| mongocxx::bulk_write_exception | when there are errors processing the writes. |
| std::int64_t mongocxx::collection::count | ( | bsoncxx::document::view_or_value | filter, |
| const options::count & | options = options::count() |
||
| ) |
Counts the number of documents matching the provided filter.
| filter | The filter that documents must match in order to be counted. |
| options | Optional arguments, see mongocxx::options::count. |
| mongocxx::query_exception | if the count operation fails. |
| bsoncxx::document::value mongocxx::collection::create_index | ( | bsoncxx::document::view_or_value | keys, |
| const options::index & | options = options::index() |
||
| ) |
Creates an index over the collection for the provided keys with the provided options.
| keys | The keys for the index: {a: 1, b: -1} |
| options | Optional arguments, see mongocxx::options::index. |
| mongocxx::logic_error | if the options are invalid. |
| mongocxx::operation_exception | if index creation fails. |
| stdx::optional<result::delete_result> mongocxx::collection::delete_many | ( | bsoncxx::document::view_or_value | filter, |
| const options::delete_options & | options = options::delete_options() |
||
| ) |
Deletes all matching documents from the collection.
| filter | Document view representing the data to be deleted. |
| options | Optional arguments, see mongocxx::options::delete_options. |
| mongocxx::bulk_write_exception | if the delete fails. |
| stdx::optional<result::delete_result> mongocxx::collection::delete_one | ( | bsoncxx::document::view_or_value | filter, |
| const options::delete_options & | options = options::delete_options() |
||
| ) |
Deletes a single matching document from the collection.
| filter | Document view representing the data to be deleted. |
| options | Optional arguments, see mongocxx::options::delete_options. |
| mongocxx::bulk_write_exception | if the delete fails. |
| cursor mongocxx::collection::distinct | ( | bsoncxx::string::view_or_value | name, |
| bsoncxx::document::view_or_value | filter, | ||
| const options::distinct & | options = options::distinct() |
||
| ) |
Finds the distinct values for a specified field accross the collection.
| field_name | The field for which the distinct values will be found. |
| filter | Document view representing the documents for which the distinct operation will apply. |
| options | Optional arguments, see options::distinct. |
| void mongocxx::collection::drop | ( | ) |
Drops this collection and all its contained documents from the database.
| mongocxx::operation_exception | if the operation fails. |
| cursor mongocxx::collection::find | ( | bsoncxx::document::view_or_value | filter, |
| const options::find & | options = options::find() |
||
| ) |
Finds the documents in this collection which match the provided filter.
| filter | Document view representing a document that should match the query. |
| options | Optional arguments, see options::find |
| mongocxx::logic_error | if the options are invalid. |
| stdx::optional<bsoncxx::document::value> mongocxx::collection::find_one | ( | bsoncxx::document::view_or_value | filter, |
| const options::find & | options = options::find() |
||
| ) |
Finds a single document in this collection that match the provided filter.
| filter | Document view representing a document that should match the query. |
| options | Optional arguments, see options::find |
| mongocxx::query_exception | if the operation fails. |
| stdx::optional<bsoncxx::document::value> mongocxx::collection::find_one_and_delete | ( | bsoncxx::document::view_or_value | filter, |
| const options::find_one_and_delete & | options = options::find_one_and_delete() |
||
| ) |
Finds a single document matching the filter, deletes it, and returns the original.
| filter | Document view representing a document that should be deleted. |
| options | Optional arguments, see options::find_one_and_delete |
| mongocxx::write_exception | if the operation fails. |
| stdx::optional<bsoncxx::document::value> mongocxx::collection::find_one_and_replace | ( | bsoncxx::document::view_or_value | filter, |
| bsoncxx::document::view_or_value | replacement, | ||
| const options::find_one_and_replace & | options = options::find_one_and_replace() |
||
| ) |
Finds a single document matching the filter, replaces it, and returns either the original or the replacement document.
| filter | Document view representing a document that should be replaced. |
| replacement | Document view representing the replacement for a matching document. |
| options | Optional arguments, see options::find_one_and_replace. |
| mongocxx::write_exception | if the operation fails. |
| stdx::optional<bsoncxx::document::value> mongocxx::collection::find_one_and_update | ( | bsoncxx::document::view_or_value | filter, |
| bsoncxx::document::view_or_value | update, | ||
| const options::find_one_and_update & | options = options::find_one_and_update() |
||
| ) |
Finds a single document matching the filter, updates it, and returns either the original or the newly-updated document.
| filter | Document view representing a document that should be updated. |
| update | Document view representing the update to apply to a matching document. |
| options | Optional arguments, see options::find_one_and_update. |
| mongocxx::write_exception | when the operation fails. |
| stdx::optional< result::insert_many > mongocxx::collection::insert_many | ( | const container_type & | container, |
| const options::insert & | options = options::insert() |
||
| ) |
Inserts multiple documents into the collection.
If any of the documents are missing identifiers the driver will generate them.
| containter_type | The container type. Must meet the requirements for the container concept with a value type of model::write. |
| container | Container of a documents to insert. |
| options | Optional arguments, see options::insert. |
| mongocxx::bulk_write_exception | when the operation fails. |
| stdx::optional< result::insert_many > mongocxx::collection::insert_many | ( | document_view_iterator_type | begin, |
| document_view_iterator_type | end, | ||
| const options::insert & | options = options::insert() |
||
| ) |
Inserts multiple documents into the collection.
If any of the documents are missing identifiers the driver will generate them.
| document_view_iterator_type | The iterator type. Must meet the requirements for the input iterator concept with a value type of bsoncxx::document::view. |
| begin | Iterator pointing to the first document to be inserted. |
| end | Iterator pointing to the end of the documents to be inserted. |
| options | Optional arguments, see options::insert. |
| mongocxx::bulk_write_exception | if the operation fails. |
TODO: document DocumentViewIterator concept or static assert
| stdx::optional<result::insert_one> mongocxx::collection::insert_one | ( | bsoncxx::document::view_or_value | document, |
| const options::insert & | options = options::insert() |
||
| ) |
Inserts a single document into the collection.
If the document is missing an identifier (_id field) one will be generated for it.
| document | The document to insert. |
| options | Optional arguments, see options::insert. |
| mongocxx::bulk_write_exception | if the operation fails. |
| cursor mongocxx::collection::list_indexes | ( | ) | const |
Returns a list of the indexes currently on this collection.
| mongocxx::operation_exception | if the operation fails. |
| stdx::string_view mongocxx::collection::name | ( | ) | const |
Returns the name of this collection as a view of a null-terminated string.
| class read_concern mongocxx::collection::read_concern | ( | ) | const |
Gets the read_concern for the collection.
If a read_concern has not been explicitly set for this collection object, it inherits the read_concern from its parent database or client object.
| void mongocxx::collection::read_concern | ( | class read_concern | rc | ) |
Sets the read_concern for this collection.
Changes will not have any effect on existing cursors or other read operations which use the previously-set read concern.
| rc | The new read_concern |
| void mongocxx::collection::read_preference | ( | class read_preference | rp | ) |
Sets the read_preference for this collection.
Changes will not have any effect on existing cursors or other read operations which use the read preference.
| rp | The read_preference to set. |
| class read_preference mongocxx::collection::read_preference | ( | ) | const |
Gets the read_preference for the collection.
| void mongocxx::collection::rename | ( | bsoncxx::string::view_or_value | new_name, |
| bool | drop_target_before_rename = false |
||
| ) |
Rename this collection.
| new_name | The new name to assign to the collection. |
| drop_target_before_rename | Whether to overwrite any existing collections called new_name. The default is false. |
| mongocxx::operation_exception | if the operation fails. |
| stdx::optional<result::replace_one> mongocxx::collection::replace_one | ( | bsoncxx::document::view_or_value | filter, |
| bsoncxx::document::view_or_value | replacement, | ||
| const options::update & | options = options::update() |
||
| ) |
Replaces a single document matching the provided filter in this collection.
| filter | Document representing the match criteria. |
| replacement | The replacement document. |
| options | Optional arguments, see options::update. |
| mongocxx::bulk_write_exception | if the operation fails. |
| stdx::optional<result::update> mongocxx::collection::update_many | ( | bsoncxx::document::view_or_value | filter, |
| bsoncxx::document::view_or_value | update, | ||
| const options::update & | options = options::update() |
||
| ) |
Updates multiple documents matching the provided filter in this collection.
| filter | Document representing the match criteria. |
| update | Document representing the update to be applied to matching documents. |
| options | Optional arguments, see options::update. |
| mongocxx::bulk_write_exception | if the update operation fails. |
| stdx::optional<result::update> mongocxx::collection::update_one | ( | bsoncxx::document::view_or_value | filter, |
| bsoncxx::document::view_or_value | update, | ||
| const options::update & | options = options::update() |
||
| ) |
Updates a single document matching the provided filter in this collection.
| filter | Document representing the match criteria. |
| update | Document representing the update to be applied to a matching document. |
| options | Optional arguments, see options::update. |
| mongocxx::bulk_write_exception | if the update operation fails. |
| class write_concern mongocxx::collection::write_concern | ( | ) | const |
Gets the write_concern for the collection.
| void mongocxx::collection::write_concern | ( | class write_concern | wc | ) |
Sets the write_concern for this collection.
Changes will not have any effect on existing write operations.
| wc | The new write_concern to use. |
1.8.10