MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
mongocxx::v1::collection Class Reference

#include <mongocxx/v1/collection.hpp>

Description

A MongoDB collection.

See also
Attention
This feature is experimental! It is not ready for use!

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::resultbulk_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::resultbulk_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_resultinsert_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_resultinsert_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.
collectionoperator= (collection &&other) noexcept
 Move assignment.
collectionoperator= (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::resultwrite (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::resultwrite (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::resultbulk_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::resultbulk_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_resultdelete_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_resultdelete_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_resultdelete_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_resultdelete_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::valuefind_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::valuefind_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::valuefind_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::valuefind_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::valuefind_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::valuefind_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::valuefind_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::valuefind_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::valuefind_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::valuefind_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_resultinsert_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_resultinsert_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_resultinsert_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_resultinsert_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_resultreplace_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_resultreplace_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_resultupdate_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_resultupdate_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_resultupdate_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_resultupdate_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_resultupdate_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_resultupdate_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_resultupdate_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_resultupdate_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.

Attention
This feature is experimental! It is not ready for use!
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() [2/2]

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

Run an aggregation framework pipeline.

See also

◆ 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();
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() [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

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ error_category()

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

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

Attention
This feature is experimental! It is not ready for use!

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ find_one_and_update() [1/4]

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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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::exceptionwith mongocxx::v1::collection::errc::max_time_u32 if the "maxTimeMS" field is not representable as an std::uint32_t.
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ indexes()

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

Manage indexes associated with this collection.

See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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

◆ 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

◆ 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::exceptionwhen a client-side or server-side error is encountered. (mongoc does not return the raw server response for this command.)
See also

◆ 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::exceptionwhen a client-side or server-side error is encountered. (mongoc does not return the raw server response for this command.)
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ search_indexes()

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

Manage Atlas Search Indexes associated with this collection.

See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.
See also

◆ 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

◆ 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

◆ 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

◆ 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

◆ 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

◆ make_error_code

std::error_code make_error_code ( errc v)
friend

Support implicit conversion to std::error_code.

Attention
This feature is experimental! It is not ready for use!

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