MongoDB C++ Driver
mongocxx-3.6.2
|
18 #include <bsoncxx/builder/basic/array.hpp>
19 #include <bsoncxx/builder/basic/document.hpp>
20 #include <bsoncxx/builder/basic/kvp.hpp>
21 #include <bsoncxx/builder/concatenate.hpp>
22 #include <bsoncxx/document/view_or_value.hpp>
23 #include <bsoncxx/oid.hpp>
24 #include <bsoncxx/stdx/optional.hpp>
25 #include <bsoncxx/string/view_or_value.hpp>
26 #include <mongocxx/bulk_write.hpp>
27 #include <mongocxx/change_stream.hpp>
28 #include <mongocxx/client_session.hpp>
29 #include <mongocxx/config/prelude.hpp>
30 #include <mongocxx/cursor.hpp>
31 #include <mongocxx/index_view.hpp>
32 #include <mongocxx/model/insert_one.hpp>
33 #include <mongocxx/options/aggregate.hpp>
34 #include <mongocxx/options/bulk_write.hpp>
35 #include <mongocxx/options/change_stream.hpp>
36 #include <mongocxx/options/count.hpp>
37 #include <mongocxx/options/delete.hpp>
38 #include <mongocxx/options/distinct.hpp>
39 #include <mongocxx/options/estimated_document_count.hpp>
40 #include <mongocxx/options/find.hpp>
41 #include <mongocxx/options/find_one_and_delete.hpp>
42 #include <mongocxx/options/find_one_and_replace.hpp>
43 #include <mongocxx/options/find_one_and_update.hpp>
44 #include <mongocxx/options/index.hpp>
45 #include <mongocxx/options/index_view.hpp>
46 #include <mongocxx/options/insert.hpp>
47 #include <mongocxx/options/replace.hpp>
48 #include <mongocxx/options/update.hpp>
49 #include <mongocxx/pipeline.hpp>
50 #include <mongocxx/read_concern.hpp>
51 #include <mongocxx/read_preference.hpp>
52 #include <mongocxx/result/bulk_write.hpp>
53 #include <mongocxx/result/delete.hpp>
54 #include <mongocxx/result/insert_many.hpp>
55 #include <mongocxx/result/insert_one.hpp>
56 #include <mongocxx/result/replace_one.hpp>
57 #include <mongocxx/result/update.hpp>
58 #include <mongocxx/write_concern.hpp>
62 MONGOCXX_INLINE_NAMESPACE_BEGIN
94 class _empty_doc_tag {
95 _empty_doc_tag() =
default;
136 explicit operator
bool() const noexcept;
160 const options::aggregate& options = options::aggregate());
185 const options::aggregate& options = options::aggregate());
244 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
245 const model::write& write,
const options::bulk_write& options = options::bulk_write());
269 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
270 const client_session& session,
271 const model::write& write,
272 const options::bulk_write& options = options::bulk_write());
300 template <
typename container_type>
301 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
302 const container_type& writes,
const options::bulk_write& options = options::bulk_write());
327 template <
typename container_type>
328 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
329 const client_session& session,
330 const container_type& writes,
331 const options::bulk_write& options = options::bulk_write());
360 template <
typename write_model_iterator_type>
361 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
362 write_model_iterator_type begin,
363 write_model_iterator_type end,
364 const options::bulk_write& options = options::bulk_write());
390 template <
typename write_model_iterator_type>
391 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
392 const client_session& session,
393 write_model_iterator_type begin,
394 write_model_iterator_type end,
395 const options::bulk_write& options = options::bulk_write());
699 const bsoncxx::stdx::optional<mongocxx::write_concern>&
write_concern = {});
978 std::initializer_list<_empty_doc_tag> update,
1062 std::initializer_list<_empty_doc_tag> update,
1135 template <
typename container_type>
1136 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1160 template <
typename container_type>
1161 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1163 const container_type& container,
1191 template <
typename document_view_iterator_type>
1192 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1193 document_view_iterator_type begin,
1194 document_view_iterator_type end,
1218 template <
typename document_view_iterator_type>
1219 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1221 document_view_iterator_type begin,
1222 document_view_iterator_type end,
1287 bool drop_target_before_rename =
false,
1288 const bsoncxx::stdx::optional<write_concern>&
write_concern = {});
1313 bool drop_target_before_rename =
false,
1314 const bsoncxx::stdx::optional<write_concern>&
write_concern = {});
1487 std::initializer_list<_empty_doc_tag> update,
1568 std::initializer_list<_empty_doc_tag> update,
1646 std::initializer_list<_empty_doc_tag> update,
1727 std::initializer_list<_empty_doc_tag> update,
1837 MONGOCXX_PRIVATE std::int64_t _count(
const client_session* session,
1841 MONGOCXX_PRIVATE std::int64_t _count_documents(
const client_session* session,
1851 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
1856 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
1866 MONGOCXX_PRIVATE
void _drop(
1868 const bsoncxx::stdx::optional<mongocxx::write_concern>&
write_concern);
1874 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one(
1879 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_delete(
1884 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_replace(
1890 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_update(
1896 MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
1901 MONGOCXX_PRIVATE
void _rename(
1904 bool drop_target_before_rename,
1905 const bsoncxx::stdx::optional<class write_concern>&
write_concern);
1907 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1912 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1918 MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
1924 MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
1935 class bulk_write _init_insert_many(const options::insert& options,
1938 void _insert_many_doc_handler(class bulk_write& writes,
1939 bsoncxx::builder::basic::array& inserted_ids,
1940 bsoncxx::document::view doc) const;
1942 stdx::optional<result::insert_many> _exec_insert_many(
1943 class bulk_write& writes, bsoncxx::builder::basic::array& inserted_ids);
1945 template <typename document_view_iterator_type>
1946 MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
1947 const client_session* session,
1948 document_view_iterator_type begin,
1949 document_view_iterator_type end,
1950 const options::insert& options);
1952 class MONGOCXX_PRIVATE impl;
1954 MONGOCXX_PRIVATE impl& _get_impl();
1955 MONGOCXX_PRIVATE const impl& _get_impl() const;
1957 std::unique_ptr<impl> _impl;
1961 const model::write& write, const options::bulk_write& options) {
1962 return create_bulk_write(options).append(write).execute();
1967 return create_bulk_write(session, options).append(write).execute();
1970 template <
typename container_type>
1971 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1973 return bulk_write(requests.begin(), requests.end(), options);
1976 template <
typename container_type>
1977 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1979 const container_type& requests,
1981 return bulk_write(session, requests.begin(), requests.end(), options);
1984 template <
typename write_model_iterator_type>
1985 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1986 write_model_iterator_type begin,
1987 write_model_iterator_type end,
1989 auto writes = create_bulk_write(options);
1990 std::for_each(begin, end, [&](
const model::write& current) { writes.append(current); });
1991 return writes.execute();
1994 template <
typename write_model_iterator_type>
1995 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1997 write_model_iterator_type begin,
1998 write_model_iterator_type end,
2000 auto writes = create_bulk_write(session, options);
2001 std::for_each(begin, end, [&](
const model::write& current) { writes.append(current); });
2002 return writes.execute();
2005 template <
typename container_type>
2008 return insert_many(container.begin(), container.end(), options);
2011 template <
typename container_type>
2014 const container_type& container,
2016 return insert_many(session, container.begin(), container.end(), options);
2019 template <
typename document_view_iterator_type>
2020 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
2023 document_view_iterator_type begin,
2024 document_view_iterator_type end,
2027 auto writes = _init_insert_many(options, session);
2029 _insert_many_doc_handler(writes, inserted_ids, doc);
2031 return _exec_insert_many(writes, inserted_ids);
2034 template <
typename document_view_iterator_type>
2036 document_view_iterator_type begin,
2037 document_view_iterator_type end,
2039 return _insert_many(
nullptr, begin, end, options);
2042 template <
typename document_view_iterator_type>
2045 document_view_iterator_type begin,
2046 document_view_iterator_type end,
2048 return _insert_many(&session, begin, end, options);
2051 MONGOCXX_INLINE_NAMESPACE_END
2054 #include <mongocxx/config/postlude.hpp>
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
stdx::optional< result::update > update_many(bsoncxx::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
stdx::optional< result::bulk_write > write(const model::write &write, const options::bulk_write &options=options::bulk_write())
Sends a write to the server as a bulk write operation.
Definition: collection.hpp:1960
stdx::optional< result::delete_result > delete_one(const client_session &session, bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes a single matching document from the collection.
stdx::optional< result::update > update_many(const client_session &session, bsoncxx::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
void drop(const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops this collection and all its contained documents from the database.
Definition: change_stream.hpp:31
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
change_stream watch(const options::change_stream &options={})
Gets a change stream on this collection with an empty pipeline.
stdx::optional< result::update > update_one(const client_session &session, bsoncxx::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
stdx::optional< result::insert_one > insert_one(bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
Class representing the optional arguments to a MongoDB aggregation operation.
Definition: aggregate.hpp:38
Class representing the optional arguments to a MongoDB insert operation.
Definition: insert.hpp:31
Class representing the optional arguments to mongocxx::collection::estimated_document_count.
Definition: estimated_document_count.hpp:32
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:56
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
collection() noexcept
Default constructs a collection object.
cursor distinct(bsoncxx::string::view_or_value name, bsoncxx::document::view_or_value filter, const options::distinct &options=options::distinct())
Finds the distinct values for a specified field across the collection.
stdx::optional< result::replace_one > replace_one(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::replace &options=options::replace{})
Replaces a single document matching the provided filter in this collection.
Class representing the optional arguments to a MongoDB find_and_modify delete operation.
Definition: find_one_and_delete.hpp:34
change_stream watch(const client_session &session, const options::change_stream &options={})
stdx::string_view name() const
Returns the name of this collection.
index_view indexes()
Gets an index_view to the collection.
cursor list_indexes(const client_session &session) const
Returns a list of the indexes currently on this collection.
Class representing the optional arguments to a MongoDB distinct command.
Definition: distinct.hpp:34
stdx::optional< result::update > update_one(bsoncxx::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
std::int64_t count_documents(const client_session &session, bsoncxx::document::view_or_value filter, const options::count &options=options::count())
Counts the number of documents matching the provided filter.
Class representing optional arguments to IndexView operations.
Definition: index_view.hpp:31
class write_concern write_concern() const
Gets the write_concern for the collection.
stdx::optional< bsoncxx::document::value > find_one(const client_session &session, bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds a single document in this collection that match the provided filter.
A class to represent the read concern.
Definition: read_concern.hpp:54
stdx::optional< result::update > update_one(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
stdx::optional< result::delete_result > delete_many(bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes all matching documents from the collection.
stdx::optional< result::insert_many > insert_many(const container_type &container, const options::insert &options=options::insert())
Inserts multiple documents into the collection.
Definition: collection.hpp:2006
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
stdx::optional< bsoncxx::document::value > find_one_and_update(bsoncxx::document::view_or_value filter, const pipeline &update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
class read_concern read_concern() const
Gets the read_concern for the collection.
Models a single write operation within a mongocxx::bulk_write.
Definition: write.hpp:37
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:62
std::int64_t count_documents(bsoncxx::document::view_or_value filter, const options::count &options=options::count())
Counts the number of documents matching the provided filter.
stdx::optional< bsoncxx::document::value > find_one_and_update(bsoncxx::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
Class representing the optional arguments to a MongoDB find_and_modify update operation.
Definition: find_one_and_update.hpp:37
stdx::optional< bsoncxx::document::value > find_one(bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds a single document in this collection that match the provided filter.
stdx::optional< result::replace_one > replace_one(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::replace &options=options::replace{})
Replaces a single document matching the provided filter in this collection.
stdx::optional< result::delete_result > delete_one(bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes a single matching document from the collection.
stdx::optional< result::delete_result > delete_many(const client_session &session, bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes all matching documents from the collection.
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:36
Definition: index_view.hpp:32
stdx::optional< result::update > update_many(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
stdx::optional< bsoncxx::document::value > find_one_and_replace(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::find_one_and_replace &options=options::find_one_and_replace())
Finds a single document matching the filter, replaces it, and returns either the original or the repl...
std::int64_t estimated_document_count(const options::estimated_document_count &options=options::estimated_document_count())
Returns an estimate of the number of documents in the collection.
stdx::optional< result::update > update_many(bsoncxx::document::view_or_value filter, const pipeline &update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
stdx::optional< bsoncxx::document::value > find_one_and_delete(bsoncxx::document::view_or_value filter, const options::find_one_and_delete &options=options::find_one_and_delete())
Finds a single document matching the filter, deletes it, and returns the original.
stdx::optional< result::update > update_one(const client_session &session, bsoncxx::document::view_or_value filter, const pipeline &update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
stdx::optional< result::insert_one > insert_one(const client_session &session, bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
Class representing the optional arguments to a MongoDB update operation.
Definition: update.hpp:33
void rename(const client_session &session, bsoncxx::string::view_or_value new_name, bool drop_target_before_rename=false, const bsoncxx::stdx::optional< write_concern > &write_concern={})
Rename this collection.
stdx::optional< bsoncxx::document::value > find_one_and_update(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:38
A traditional builder-style interface for constructing a BSON array.
Definition: array.hpp:35
Definition: change_stream.hpp:35
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:39
Class representing a batch of write operations that can be sent to the server as a group.
Definition: bulk_write.hpp:43
cursor find(const client_session &session, bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds the documents in this collection which match the provided filter.
Class representing a MongoDB database.
Definition: database.hpp:43
cursor find(bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds the documents in this collection which match the provided filter.
stdx::optional< result::update > update_many(const client_session &session, bsoncxx::document::view_or_value filter, const pipeline &update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
stdx::optional< result::update > update_one(bsoncxx::document::view_or_value filter, const pipeline &update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
stdx::optional< bsoncxx::document::value > find_one_and_update(const client_session &session, bsoncxx::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
stdx::optional< bsoncxx::document::value > find_one_and_update(const client_session &session, bsoncxx::document::view_or_value filter, const pipeline &update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
stdx::optional< bsoncxx::document::value > find_one_and_delete(const client_session &session, bsoncxx::document::view_or_value filter, const options::find_one_and_delete &options=options::find_one_and_delete())
Finds a single document matching the filter, deletes it, and returns the original.
Class representing the optional arguments to a MongoDB delete operation.
Definition: delete.hpp:31
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:81
Class representing a MongoDB update operation that replaces a single document.
Definition: replace_one.hpp:31
bsoncxx::document::value create_index(const client_session &session, bsoncxx::document::view_or_value keys, bsoncxx::document::view_or_value index_options={}, options::index_view operation_options=options::index_view{})
Creates an index over the collection for the provided keys with the provided options.
stdx::optional< result::update > update_one(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
Class representing the optional arguments to a MongoDB replace operation.
Definition: replace.hpp:33
stdx::optional< bsoncxx::document::value > find_one_and_update(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
void drop(const client_session &session, const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops this collection and all its contained documents from the database.
Class representing the optional arguments to a MongoDB bulk write.
Definition: bulk_write.hpp:29
Class representing the optional arguments to a MongoDB find_and_modify replace operation.
Definition: find_one_and_replace.hpp:36
stdx::optional< result::update > update_many(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
Class representing the optional arguments to mongocxx::collection::count_documents.
Definition: count.hpp:36
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36
class read_preference read_preference() const
Gets the read_preference for the collection.
cursor list_indexes() const
Returns a list of the indexes currently on this collection.
bsoncxx::document::value create_index(bsoncxx::document::view_or_value keys, bsoncxx::document::view_or_value index_options={}, options::index_view operation_options=options::index_view{})
Creates an index over the collection for the provided keys with the provided options.
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
cursor distinct(const client_session &session, bsoncxx::string::view_or_value name, bsoncxx::document::view_or_value filter, const options::distinct &options=options::distinct())
Finds the distinct values for a specified field across the collection.
void rename(bsoncxx::string::view_or_value new_name, bool drop_target_before_rename=false, const bsoncxx::stdx::optional< write_concern > &write_concern={})
Rename this collection.
stdx::optional< bsoncxx::document::value > find_one_and_replace(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::find_one_and_replace &options=options::find_one_and_replace())
Finds a single document matching the filter, replaces it, and returns either the original or the repl...