Loading...
Searching...
No Matches
mongocxx::v1::collection Class Reference

`#include <mongocxx/v1/collection.hpp>`

## Description

A MongoDB collection.

See also
  - Databases and Collections in MongoDB (MongoDB Manual)

## Public Types

enum class | errc
| Errors codes which may be returned by mongocxx::v1::collection. More...

## Public Member Functions

| collection ()
| Default initialization.
| collection (collection &&other) noexcept
| Move constructor.
| collection (collection const &other)
| Copy construction.
| ~collection ()
| Destroy this object.
template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::bulk_write::result > | bulk_write (Container const &writes, v1::bulk_write::options const &opts={})
| Equivalent to this->bulk_write(writes.begin(), writes.begin(), opts).
template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::bulk_write::result > | bulk_write (v1::client_session const &session, Container const &writes, v1::bulk_write::options const &opts={})
| Equivalent to this->bulk_write(session, writes.begin(), writes.begin(), opts).
bsoncxx::v1::stdx::optional< std::string > | create_index (bsoncxx::v1::document::value keys, bsoncxx::v1::document::value index_opts={}, v1::indexes::create_one_options const &create_opts={})
| Equivalent to this->indexes().create_one(keys, index_opts, create_opts).
bsoncxx::v1::stdx::optional< std::string > | create_index (v1::client_session const &session, bsoncxx::v1::document::value keys, bsoncxx::v1::document::value index_opts={}, v1::indexes::create_one_options const &create_opts={})
| Equivalent to this->indexes().create_one(session, keys, index_opts, create_opts).
std::int64_t | estimated_document_count (v1::estimated_document_count_options const &opts={})
| Return an estimate of the number of documents in this collection using collection metadata.
v1::indexes | indexes ()
| Manage indexes associated with this collection.
template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::insert_many_result > | insert_many (Container const &docs, v1::insert_many_options const &opts={})
| Equivalent to this->insert_many(docs.begin(), docs.end(), opts).
template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::insert_many_result > | insert_many (v1::client_session const &session, Container const &docs, v1::insert_many_options const &opts={})
| Equivalent to this->insert_many(session, docs.begin(), docs.end(), opts).
v1::cursor | list_indexes ()
| Equivalent to this->indexes.list().
v1::cursor | list_indexes (v1::client_session const &session)
| Equivalent to this->indexes.list(session).
bsoncxx::v1::stdx::string_view | name () const
| Return the name of this collection.
| operator bool () const
| Return true when *this is NOT in an assign-or-destroy-only state.
collection & | operator= (collection &&other) noexcept
| Move assignment.
collection & | operator= (collection const &other)
| Copy assignment.
v1::read_concern | read_concern () const
| Return the current default "readConcern" to use for operations on this collection.
void | read_concern (v1::read_concern const &rc)
| Set the default "readConcern" to use for operations on this collection.
v1::read_preference | read_preference () const
| Return the current default "readPreference" to use for operations on this collection.
void | read_preference (v1::read_preference const &rp)
| Set the default "readPreference" to use for operations on this collection.
v1::search_indexes | search_indexes ()
| Manage Atlas Search Indexes associated with this collection.
v1::write_concern | write_concern () const
| Return the current default "writeConcern" to use for operations on this collection.
void | write_concern (v1::write_concern const &wc)
| Set the default "writeConcern" to use for operations on this collection.
v1::cursor | aggregate (v1::pipeline const &pipeline, v1::aggregate_options const &opts={})
| Run an aggregation framework pipeline.
v1::cursor | aggregate (v1::client_session const &session, v1::pipeline const &pipeline, v1::aggregate_options const &opts={})
| Run an aggregation framework pipeline.
v1::bulk_write | create_bulk_write (v1::bulk_write::options const &opts={})
| Create a bulk write operation.
v1::bulk_write | create_bulk_write (v1::client_session const &session, v1::bulk_write::options const &opts={})
| Create a bulk write operation.
bsoncxx::v1::stdx::optional< v1::bulk_write::result > | write (v1::bulk_write::single const &write, v1::bulk_write::options const &opts={})
| Equivalent to this->bulk_write(...) with a single write operation.
bsoncxx::v1::stdx::optional< v1::bulk_write::result > | write (v1::client_session const &session, v1::bulk_write::single const &write, v1::bulk_write::options const &opts={})
| Equivalent to this->bulk_write(...) with a single write operation.
template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_write_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::bulk_write::result > | bulk_write (InputIt begin, Sentinel end, v1::bulk_write::options const &opts={})
| Execute multiple write operations.
template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_write_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::bulk_write::result > | bulk_write (v1::client_session const &session, InputIt begin, Sentinel end, v1::bulk_write::options const &opts={})
| Execute multiple write operations.
std::int64_t | count_documents (bsoncxx::v1::document::view filter, v1::count_options const &opts={})
| Return the number of documents in this collection that match the given query filter.
std::int64_t | count_documents (v1::client_session const &session, bsoncxx::v1::document::view filter, v1::count_options const &opts={})
| Return the number of documents in this collection that match the given query filter.
bsoncxx::v1::stdx::optional< v1::delete_many_result > | delete_many (bsoncxx::v1::document::view q, v1::delete_many_options const &opts={})
| Delete multiple documents in this collection using the given query filter.
bsoncxx::v1::stdx::optional< v1::delete_many_result > | delete_many (v1::client_session const &session, bsoncxx::v1::document::view q, v1::delete_many_options const &opts={})
| Delete multiple documents in this collection using the given query filter.
bsoncxx::v1::stdx::optional< v1::delete_one_result > | delete_one (bsoncxx::v1::document::view q, v1::delete_one_options const &opts={})
| Delete a single document in this collection using the given query filter.
bsoncxx::v1::stdx::optional< v1::delete_one_result > | delete_one (v1::client_session const &session, bsoncxx::v1::document::view q, v1::delete_one_options const &opts={})
| Delete a single document in this collection using the given query filter.
v1::cursor | distinct (bsoncxx::v1::stdx::string_view key, bsoncxx::v1::document::view query, v1::distinct_options const &opts={})
| Return the distinct values for the specified field within this collection.
v1::cursor | distinct (v1::client_session const &session, bsoncxx::v1::stdx::string_view key, bsoncxx::v1::document::view query, v1::distinct_options const &opts={})
| Return the distinct values for the specified field within this collection.
void | drop (bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={}, bsoncxx::v1::document::view opts={})
| Drop this collection.
void | drop (v1::client_session const &session, bsoncxx::v1::stdx::optional< v1::write_concern > const &wc={}, bsoncxx::v1::document::view opts={})
| Drop this collection.
v1::cursor | find (bsoncxx::v1::document::view filter, v1::find_options const &opts={})
| Find documents in this collection matching the given query filter.
v1::cursor | find (v1::client_session const &session, bsoncxx::v1::document::view filter, v1::find_options const &opts={})
| Find documents in this collection matching the given query filter.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | find_one (bsoncxx::v1::document::view filter, v1::find_options const &opts={})
| Return the first matching document obtained by this->find(...).
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | find_one (v1::client_session const &session, bsoncxx::v1::document::view filter, v1::find_options const &opts={})
| Return the first matching document obtained by this->find(...).
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | find_one_and_delete (bsoncxx::v1::document::view query, v1::find_one_and_delete_options const &opts={})
| Find a single document in this collection and delete it, returning the original document.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | 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 delete it, returning the original document.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | find_one_and_replace (bsoncxx::v1::document::view query, bsoncxx::v1::document::view replacement, v1::find_one_and_replace_options const &opts={})
| Find a single document in this collection and replace it.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | find_one_and_replace (v1::client_session const &session, bsoncxx::v1::document::view query, bsoncxx::v1::document::view replacement, v1::find_one_and_replace_options const &opts={})
| Find a single document in this collection and replace it.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | find_one_and_update (bsoncxx::v1::document::view query, bsoncxx::v1::document::view update, v1::find_one_and_update_options const &opts={})
| Find a single document in this collection and update it.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | find_one_and_update (bsoncxx::v1::document::view query, v1::pipeline const &update, v1::find_one_and_update_options const &opts={})
| Find a single document in this collection and update it.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | 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={})
| Find a single document in this collection and update it.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > | 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={})
| Find a single document in this collection and update it.
bsoncxx::v1::stdx::optional< v1::insert_one_result > | insert_one (bsoncxx::v1::document::view document, v1::insert_one_options const &opts={})
| Insert a single document into this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::insert_one_result > | insert_one (v1::client_session const &session, bsoncxx::v1::document::view document, v1::insert_one_options const &opts={})
| Insert a single document into this collection as a bulk write operation.
template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_document_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::insert_many_result > | insert_many (InputIt begin, Sentinel end, v1::insert_many_options const &opts={})
| Insert the given documents into this collection as a bulk write operation.
template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_document_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>
bsoncxx::v1::stdx::optional< v1::insert_many_result > | insert_many (v1::client_session const &session, InputIt begin, Sentinel end, v1::insert_many_options const &opts={})
| Insert the given documents into this collection as a bulk write operation.
void | rename (bsoncxx::v1::stdx::string_view new_name, bool drop_target=false, bsoncxx::v1::stdx::optional< v1::write_concern > const &write_concern={})
| Change the name of this collection.
void | rename (v1::client_session const &session, bsoncxx::v1::stdx::string_view new_name, bool drop_target=false, bsoncxx::v1::stdx::optional< v1::write_concern > const &write_concern={})
| Change the name of this collection.
bsoncxx::v1::stdx::optional< v1::replace_one_result > | replace_one (bsoncxx::v1::document::view filter, bsoncxx::v1::document::value replacement, v1::replace_one_options const &opts={})
| Replace a single document in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::replace_one_result > | replace_one (v1::client_session const &session, bsoncxx::v1::document::view filter, bsoncxx::v1::document::value replacement, v1::replace_one_options const &opts={})
| Replace a single document in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_many_result > | update_many (bsoncxx::v1::document::view filter, bsoncxx::v1::document::view update, v1::update_many_options const &opts={})
| Update multiple documents in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_many_result > | update_many (bsoncxx::v1::document::view filter, v1::pipeline const &update, update_many_options const &opts={})
| Update multiple documents in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_many_result > | update_many (v1::client_session const &session, bsoncxx::v1::document::view filter, bsoncxx::v1::document::view update, v1::update_many_options const &opts={})
| Update multiple documents in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_many_result > | update_many (v1::client_session const &session, bsoncxx::v1::document::view filter, v1::pipeline const &update, v1::update_many_options const &opts={})
| Update multiple documents in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_one_result > | update_one (bsoncxx::v1::document::view filter, bsoncxx::v1::document::view update, v1::update_one_options const &opts={})
| Update a single document in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_one_result > | update_one (bsoncxx::v1::document::view filter, v1::pipeline const &update, update_one_options const &opts={})
| Update a single document in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_one_result > | update_one (v1::client_session const &session, bsoncxx::v1::document::view filter, bsoncxx::v1::document::view update, v1::update_one_options const &opts={})
| Update a single document in this collection as a bulk write operation.
bsoncxx::v1::stdx::optional< v1::update_one_result > | update_one (v1::client_session const &session, bsoncxx::v1::document::view filter, v1::pipeline const &update, v1::update_one_options const &opts={})
| Update a single document in this collection as a bulk write operation.
v1::change_stream | watch (v1::change_stream::options const &opts={})
| Return a change stream subscribed to this collection.
v1::change_stream | watch (v1::client_session const &session, v1::change_stream::options const &opts={})
| Return a change stream subscribed to this collection.
v1::change_stream | watch (v1::pipeline const &pipeline, v1::change_stream::options const &opts={})
| Return a change stream subscribed to this collection with events filtered/modified by pipeline.
v1::change_stream | watch (v1::client_session const &session, v1::pipeline const &pipeline, v1::change_stream::options const &opts={})
| Return a change stream subscribed to this collection with events filtered/modified by pipeline.

## Static Public Member Functions

static std::error_category const & | error_category ()
| The error category for mongocxx::v1::collection::errc.

## Friends

std::error_code | make_error_code (errc v)
| Support implicit conversion to std::error_code.

## Member Enumeration Documentation

## errc

enum class mongocxx::v1::collection::errc

strong

Errors codes which may be returned by mongocxx::v1::collection.

Enumerator
zero | Zero.
max_time_u32 | The "maxTimeMS" field must be representable as an std::uint32_t.

## Constructor & Destructor Documentation

## ~collection()

mongocxx::v1::collection::~collection | ( |  | ) |

Destroy this object.

Warning
  Invalidates all associated views, cursors, bulk writes, indexes, and change streams.

## collection() [1/3]

mongocxx::v1::collection::collection | ( | collection && | other | ) |

noexcept

Move constructor.

Postconditions:
  - other is in an assign-or-destroy-only state.

## collection() [2/3]

mongocxx::v1::collection::collection | ( | collection const & | other | ) |

Copy construction.

## collection() [3/3]

mongocxx::v1::collection::collection | ( |  | ) |

Default initialization.

Postconditions:
  - *this is in an assign-or-destroy-only state.

## Member Function Documentation

## aggregate() [1/2]

v1::cursor mongocxx::v1::collection::aggregate | ( | v1::client_session const & | session,
|  | v1::pipeline const & | pipeline,
|  | v1::aggregate_options const & | opts = {} )

Run an aggregation framework pipeline.

See also
  - aggregate (database command) (MongoDB Manual)

## aggregate() [2/2]

v1::cursor mongocxx::v1::collection::aggregate | ( | v1::pipeline const & | pipeline,
|  | v1::aggregate_options const & | opts = {} )

Run an aggregation framework pipeline.

See also
  - aggregate (database command) (MongoDB Manual)

## bulk_write() [1/4]

template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::bulk_write::result > mongocxx::v1::collection::bulk_write | ( | Container const & | writes,
|  | v1::bulk_write::options const & | opts = {} )

inline

Equivalent to this->bulk_write(writes.begin(), writes.begin(), opts).

Constraints:
  - writes.begin() and writes.end() must be valid.

## bulk_write() [2/4]

template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_write_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::bulk_write::result > mongocxx::v1::collection::bulk_write | ( | InputIt | begin,
|  | Sentinel | end,
|  | v1::bulk_write::options const & | opts = {} )

inline

Execute multiple write operations.

Equivalent to:

auto bulk = this->create_bulk_write(...);
for (auto iter = begin; iter != end; ++iter) {
bulk.append(*iter);
}
return bulk.execute();
mongocxx::v1::collection::create_bulk_write
v1::bulk_write create_bulk_write(v1::bulk_write::options const &opts={})
Create a bulk write operation.

Constraints:
  - InputIt satisfies Cpp17InputIterator.
  - The value type of InputIt is convertible to mongocxx::v1::bulk_write::single.
  - Sentinel satisfies std::sentinel_for<Sentinel, InputIt>.

See also
  - Bulk Write Operations (MongoDB Manual)

## bulk_write() [3/4]

template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::bulk_write::result > mongocxx::v1::collection::bulk_write | ( | v1::client_session const & | session,
|  | Container const & | writes,
|  | v1::bulk_write::options const & | opts = {} )

inline

Equivalent to this->bulk_write(session, writes.begin(), writes.begin(), opts).

Constraints:
  - writes.begin() and writes.end() must be valid.

## bulk_write() [4/4]

template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_write_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::bulk_write::result > mongocxx::v1::collection::bulk_write | ( | v1::client_session const & | session,
|  | InputIt | begin,
|  | Sentinel | end,
|  | v1::bulk_write::options const & | opts = {} )

inline

Execute multiple write operations.

Equivalent to:

auto bulk = this->create_bulk_write(...);
for (auto iter = begin; iter != end; ++iter) {
bulk.append(*iter);
}
return bulk.execute();

Constraints:
  - InputIt satisfies Cpp17InputIterator.
  - The value type of InputIt is convertible to mongocxx::v1::bulk_write::single.
  - Sentinel satisfies std::sentinel_for<Sentinel, InputIt>.

See also
  - Bulk Write Operations (MongoDB Manual)

## count_documents() [1/2]

std::int64_t mongocxx::v1::collection::count_documents | ( | bsoncxx::v1::document::view | filter,
|  | v1::count_options const & | opts = {} )

Return the number of documents in this collection that match the given query filter.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - CRUD API (MongoDB Specifications)
  - $group (aggregation stage) (MongoDB Manual)

## count_documents() [2/2]

std::int64_t mongocxx::v1::collection::count_documents | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | v1::count_options const & | opts = {} )

Return the number of documents in this collection that match the given query filter.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - CRUD API (MongoDB Specifications)
  - $group (aggregation stage) (MongoDB Manual)

## create_bulk_write() [1/2]

v1::bulk_write mongocxx::v1::collection::create_bulk_write | ( | v1::bulk_write::options const & | opts = {} | ) |

Create a bulk write operation.

The bulk write operation must be executed with mongocxx::v1::bulk_write::execute().

## create_bulk_write() [2/2]

v1::bulk_write mongocxx::v1::collection::create_bulk_write | ( | v1::client_session const & | session,
|  | v1::bulk_write::options const & | opts = {} )

Create a bulk write operation.

The bulk write operation must be executed with mongocxx::v1::bulk_write::execute().

## create_index() [1/2]

bsoncxx::v1::stdx::optional< std::string > mongocxx::v1::collection::create_index | ( | bsoncxx::v1::document::value | keys,
|  | bsoncxx::v1::document::value | index_opts = {},
|  | v1::indexes::create_one_options const & | create_opts = {} )

inline

Equivalent to this->indexes().create_one(keys, index_opts, create_opts).

## create_index() [2/2]

bsoncxx::v1::stdx::optional< std::string > mongocxx::v1::collection::create_index | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::value | keys,
|  | bsoncxx::v1::document::value | index_opts = {},
|  | v1::indexes::create_one_options const & | create_opts = {} )

inline

Equivalent to this->indexes().create_one(session, keys, index_opts, create_opts).

## delete_many() [1/2]

bsoncxx::v1::stdx::optional< v1::delete_many_result > mongocxx::v1::collection::delete_many | ( | bsoncxx::v1::document::view | q,
|  | v1::delete_many_options const & | opts = {} )

Delete multiple documents in this collection using the given query filter.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - delete (database command) (MongoDB Manual)

## delete_many() [2/2]

bsoncxx::v1::stdx::optional< v1::delete_many_result > mongocxx::v1::collection::delete_many | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | q,
|  | v1::delete_many_options const & | opts = {} )

Delete multiple documents in this collection using the given query filter.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - delete (database command) (MongoDB Manual)

## delete_one() [1/2]

bsoncxx::v1::stdx::optional< v1::delete_one_result > mongocxx::v1::collection::delete_one | ( | bsoncxx::v1::document::view | q,
|  | v1::delete_one_options const & | opts = {} )

Delete a single document in this collection using the given query filter.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - delete (database command) (MongoDB Manual)

## delete_one() [2/2]

bsoncxx::v1::stdx::optional< v1::delete_one_result > mongocxx::v1::collection::delete_one | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | q,
|  | v1::delete_one_options const & | opts = {} )

Delete a single document in this collection using the given query filter.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - delete (database command) (MongoDB Manual)

## distinct() [1/2]

v1::cursor mongocxx::v1::collection::distinct | ( | bsoncxx::v1::stdx::string_view | key,
|  | bsoncxx::v1::document::view | query,
|  | v1::distinct_options const & | opts = {} )

Return the distinct values for the specified field within this collection.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - distinct (database command) (MongoDB Manual)

## distinct() [2/2]

v1::cursor mongocxx::v1::collection::distinct | ( | v1::client_session const & | session,
|  | bsoncxx::v1::stdx::string_view | key,
|  | bsoncxx::v1::document::view | query,
|  | v1::distinct_options const & | opts = {} )

Return the distinct values for the specified field within this collection.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - distinct (database command) (MongoDB Manual)

## drop() [1/2]

void mongocxx::v1::collection::drop | ( | bsoncxx::v1::stdx::optional< v1::write_concern > const & | wc = {},
|  | bsoncxx::v1::document::view | opts = {} )

Drop this collection.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - drop (database command) (MongoDB Manual)

## drop() [2/2]

void mongocxx::v1::collection::drop | ( | v1::client_session const & | session,
|  | bsoncxx::v1::stdx::optional< v1::write_concern > const & | wc = {},
|  | bsoncxx::v1::document::view | opts = {} )

Drop this collection.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - drop (database command) (MongoDB Manual)

## error_category()

std::error_category const & mongocxx::v1::collection::error_category | ( |  | ) |

static

The error category for mongocxx::v1::collection::errc.

## estimated_document_count()

std::int64_t mongocxx::v1::collection::estimated_document_count | ( | v1::estimated_document_count_options const & | opts = {} | ) |

Return an estimate of the number of documents in this collection using collection metadata.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - CRUD API (MongoDB Specifications)
  - count (database command) (MongoDB Manual)

## find() [1/2]

v1::cursor mongocxx::v1::collection::find | ( | bsoncxx::v1::document::view | filter,
|  | v1::find_options const & | opts = {} )

Find documents in this collection matching the given query filter.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - find (database command) (MongoDB Manual)

## find() [2/2]

v1::cursor mongocxx::v1::collection::find | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | v1::find_options const & | opts = {} )

Find documents in this collection matching the given query filter.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - find (database command) (MongoDB Manual)

## find_one() [1/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::find_one | ( | 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.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - find (database command) (MongoDB Manual)

## find_one() [2/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::find_one | ( | 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.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - find (database command) (MongoDB Manual)

## find_one_and_delete() [1/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::find_one_and_delete | ( | bsoncxx::v1::document::view | query,
|  | v1::find_one_and_delete_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.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## find_one_and_delete() [2/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::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 delete it, returning the original document.

Returns
  Empty when no matching document was found.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## find_one_and_replace() [1/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::find_one_and_replace | ( | bsoncxx::v1::document::view | query,
|  | bsoncxx::v1::document::view | replacement,
|  | v1::find_one_and_replace_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.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## find_one_and_replace() [2/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::find_one_and_replace | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | query,
|  | bsoncxx::v1::document::view | replacement,
|  | v1::find_one_and_replace_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.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## find_one_and_update() [1/4]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::find_one_and_update | ( | bsoncxx::v1::document::view | query,
|  | bsoncxx::v1::document::view | update,
|  | v1::find_one_and_update_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.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## find_one_and_update() [2/4]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::find_one_and_update | ( | bsoncxx::v1::document::view | query,
|  | v1::pipeline const & | update,
|  | v1::find_one_and_update_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.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## find_one_and_update() [3/4]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::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 = {} )

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.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## find_one_and_update() [4/4]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::value > mongocxx::v1::collection::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 = {} )

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.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - findAndModify (database command) (MongoDB Manual)

## indexes()

v1::indexes mongocxx::v1::collection::indexes | ( |  | ) |

Manage indexes associated with this collection.

See also
  - Indexes (MongoDB Manual)

## insert_many() [1/4]

template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::insert_many_result > mongocxx::v1::collection::insert_many | ( | Container const & | docs,
|  | v1::insert_many_options const & | opts = {} )

inline

Equivalent to this->insert_many(docs.begin(), docs.end(), opts).

## insert_many() [2/4]

template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_document_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::insert_many_result > mongocxx::v1::collection::insert_many | ( | InputIt | begin,
|  | Sentinel | end,
|  | v1::insert_many_options const & | opts = {} )

inline

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 bsoncxx::v1::oid.

Constraints:
  - InputIt satisfies Cpp17InputIterator.
  - The value type of InputIt is convertible to bsoncxx::v1::document::view.
  - Sentinel satisfies std::is_sentinel_for<Sentinel, InputIt>.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## insert_many() [3/4]

template<typename Container, bsoncxx::detail::enable_if_t< is_container< Container >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::insert_many_result > mongocxx::v1::collection::insert_many | ( | v1::client_session const & | session,
|  | Container const & | docs,
|  | v1::insert_many_options const & | opts = {} )

inline

Equivalent to this->insert_many(session, docs.begin(), docs.end(), opts).

## insert_many() [4/4]

template<typename InputIt, typename Sentinel, bsoncxx::detail::enable_if_t< is_document_iter< InputIt >::value &&is_sentinel_for< Sentinel, InputIt >::value > * = nullptr>

bsoncxx::v1::stdx::optional< v1::insert_many_result > mongocxx::v1::collection::insert_many | ( | v1::client_session const & | session,
|  | InputIt | begin,
|  | Sentinel | end,
|  | v1::insert_many_options const & | opts = {} )

inline

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 bsoncxx::v1::oid.

Constraints:
  - InputIt satisfies Cpp17InputIterator.
  - The value type of InputIt is convertible to bsoncxx::v1::document::view.
  - Sentinel satisfies std::is_sentinel_for<Sentinel, InputIt>.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## insert_one() [1/2]

bsoncxx::v1::stdx::optional< v1::insert_one_result > mongocxx::v1::collection::insert_one | ( | bsoncxx::v1::document::view | document,
|  | v1::insert_one_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 bsoncxx::v1::oid.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## insert_one() [2/2]

bsoncxx::v1::stdx::optional< v1::insert_one_result > mongocxx::v1::collection::insert_one | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | document,
|  | v1::insert_one_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 bsoncxx::v1::oid.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## list_indexes() [1/2]

v1::cursor mongocxx::v1::collection::list_indexes | ( |  | ) |

inline

Equivalent to this->indexes.list().

## list_indexes() [2/2]

v1::cursor mongocxx::v1::collection::list_indexes | ( | v1::client_session const & | session | ) |

inline

Equivalent to this->indexes.list(session).

## name()

bsoncxx::v1::stdx::string_view mongocxx::v1::collection::name | ( |  | ) | const

Return the name of this collection.

## operator bool()

mongocxx::v1::collection::operator bool | ( |  | ) | const

explicit

Return true when *this is NOT in an assign-or-destroy-only state.

## operator=() [1/2]

collection & mongocxx::v1::collection::operator= | ( | collection && | other | ) |

noexcept

Move assignment.

Postconditions:
  - other is in an assign-or-destroy-only state.

## operator=() [2/2]

collection & mongocxx::v1::collection::operator= | ( | collection const & | other | ) |

Copy assignment.

## read_concern() [1/2]

v1::read_concern mongocxx::v1::collection::read_concern | ( |  | ) | const

Return the current default "readConcern" to use for operations on this collection.

## read_concern() [2/2]

void mongocxx::v1::collection::read_concern | ( | v1::read_concern const & | rc | ) |

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 also
  - Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)

## read_preference() [1/2]

v1::read_preference mongocxx::v1::collection::read_preference | ( |  | ) | const

Return the current default "readPreference" to use for operations on this collection.

## read_preference() [2/2]

void mongocxx::v1::collection::read_preference | ( | v1::read_preference const & | rp | ) |

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 also
  - Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)

## rename() [1/2]

void mongocxx::v1::collection::rename | ( | bsoncxx::v1::stdx::string_view | new_name,
|  | bool | drop_target = false,
|  | bsoncxx::v1::stdx::optional< v1::write_concern > const & | write_concern = {} )

Change the name of this collection.

Exceptions

  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 also
  - renameCollection (database command) (MongoDB Manual)

## rename() [2/2]

void mongocxx::v1::collection::rename | ( | v1::client_session const & | session,
|  | bsoncxx::v1::stdx::string_view | new_name,
|  | bool | drop_target = false,
|  | bsoncxx::v1::stdx::optional< v1::write_concern > const & | write_concern = {} )

Change the name of this collection.

Exceptions

  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 also
  - renameCollection (database command) (MongoDB Manual)

## replace_one() [1/2]

bsoncxx::v1::stdx::optional< v1::replace_one_result > mongocxx::v1::collection::replace_one | ( | bsoncxx::v1::document::view | filter,
|  | bsoncxx::v1::document::value | replacement,
|  | v1::replace_one_options const & | opts = {} )

Replace a single document in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## replace_one() [2/2]

bsoncxx::v1::stdx::optional< v1::replace_one_result > mongocxx::v1::collection::replace_one | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | bsoncxx::v1::document::value | replacement,
|  | v1::replace_one_options const & | opts = {} )

Replace a single document in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## search_indexes()

v1::search_indexes mongocxx::v1::collection::search_indexes | ( |  | ) |

Manage Atlas Search Indexes associated with this collection.

See also
  - Manage MongoDB Search Indexes (MongoDB Manual)

## update_many() [1/4]

bsoncxx::v1::stdx::optional< v1::update_many_result > mongocxx::v1::collection::update_many | ( | bsoncxx::v1::document::view | filter,
|  | bsoncxx::v1::document::view | update,
|  | v1::update_many_options const & | opts = {} )

Update multiple documents in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## update_many() [2/4]

bsoncxx::v1::stdx::optional< v1::update_many_result > mongocxx::v1::collection::update_many | ( | bsoncxx::v1::document::view | filter,
|  | v1::pipeline const & | update,
|  | update_many_options const & | opts = {} )

Update multiple documents in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## update_many() [3/4]

bsoncxx::v1::stdx::optional< v1::update_many_result > mongocxx::v1::collection::update_many | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | bsoncxx::v1::document::view | update,
|  | v1::update_many_options const & | opts = {} )

Update multiple documents in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## update_many() [4/4]

bsoncxx::v1::stdx::optional< v1::update_many_result > mongocxx::v1::collection::update_many | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | v1::pipeline const & | update,
|  | v1::update_many_options const & | opts = {} )

Update multiple documents in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## update_one() [1/4]

bsoncxx::v1::stdx::optional< v1::update_one_result > mongocxx::v1::collection::update_one | ( | bsoncxx::v1::document::view | filter,
|  | bsoncxx::v1::document::view | update,
|  | v1::update_one_options const & | opts = {} )

Update a single document in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## update_one() [2/4]

bsoncxx::v1::stdx::optional< v1::update_one_result > mongocxx::v1::collection::update_one | ( | bsoncxx::v1::document::view | filter,
|  | v1::pipeline const & | update,
|  | update_one_options const & | opts = {} )

Update a single document in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## update_one() [3/4]

bsoncxx::v1::stdx::optional< v1::update_one_result > mongocxx::v1::collection::update_one | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | bsoncxx::v1::document::view | update,
|  | v1::update_one_options const & | opts = {} )

Update a single document in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## update_one() [4/4]

bsoncxx::v1::stdx::optional< v1::update_one_result > mongocxx::v1::collection::update_one | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | v1::pipeline const & | update,
|  | v1::update_one_options const & | opts = {} )

Update a single document in this collection as a bulk write operation.

Returns
  Empty when the bulk write operation is unacknowledged.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

See also
  - Bulk Write Operations (MongoDB Manual)

## watch() [1/4]

v1::change_stream mongocxx::v1::collection::watch | ( | v1::change_stream::options const & | opts = {} | ) |

Return a change stream subscribed to this collection.

See also
  - Change Streams (MongoDB Manual)

## watch() [2/4]

v1::change_stream mongocxx::v1::collection::watch | ( | v1::client_session const & | session,
|  | v1::change_stream::options const & | opts = {} )

Return a change stream subscribed to this collection.

See also
  - Change Streams (MongoDB Manual)

## watch() [3/4]

v1::change_stream mongocxx::v1::collection::watch | ( | v1::client_session const & | session,
|  | v1::pipeline const & | pipeline,
|  | v1::change_stream::options const & | opts = {} )

Return a change stream subscribed to this collection with events filtered/modified by pipeline.

See also
  - Change Streams (MongoDB Manual)

## watch() [4/4]

v1::change_stream mongocxx::v1::collection::watch | ( | v1::pipeline const & | pipeline,
|  | v1::change_stream::options const & | opts = {} )

Return a change stream subscribed to this collection with events filtered/modified by pipeline.

See also
  - Change Streams (MongoDB Manual)

## write() [1/2]

bsoncxx::v1::stdx::optional< v1::bulk_write::result > mongocxx::v1::collection::write | ( | v1::bulk_write::single const & | write,
|  | v1::bulk_write::options const & | opts = {} )

inline

Equivalent to this->bulk_write(...) with a single write operation.

## write() [2/2]

bsoncxx::v1::stdx::optional< v1::bulk_write::result > mongocxx::v1::collection::write | ( | v1::client_session const & | session,
|  | v1::bulk_write::single const & | write,
|  | v1::bulk_write::options const & | opts = {} )

inline

Equivalent to this->bulk_write(...) with a single write operation.

## write_concern() [1/2]

v1::write_concern mongocxx::v1::collection::write_concern | ( |  | ) | const

Return the current default "writeConcern" to use for operations on this collection.

## write_concern() [2/2]

void mongocxx::v1::collection::write_concern | ( | v1::write_concern const & | wc | ) |

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 also
  - Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)

## Friends And Related Symbol Documentation

## make_error_code

std::error_code make_error_code | ( | errc | v | ) |

friend

Support implicit conversion to std::error_code.

The documentation for this class was generated from the following file:

- mongocxx/v1/collection.hpp