MongoDB C++ Driver mongocxx-3.7.0
Loading...
Searching...
No Matches
collection.hpp
1// Copyright 2014-present MongoDB Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <algorithm>
18#include <string>
19
20#include <bsoncxx/builder/basic/array.hpp>
21#include <bsoncxx/builder/basic/document.hpp>
22#include <bsoncxx/builder/basic/kvp.hpp>
23#include <bsoncxx/builder/concatenate.hpp>
24#include <bsoncxx/document/view_or_value.hpp>
25#include <bsoncxx/oid.hpp>
26#include <bsoncxx/stdx/optional.hpp>
27#include <bsoncxx/string/view_or_value.hpp>
28#include <mongocxx/bulk_write.hpp>
29#include <mongocxx/change_stream.hpp>
30#include <mongocxx/client_session.hpp>
31#include <mongocxx/cursor.hpp>
32#include <mongocxx/index_view.hpp>
33#include <mongocxx/model/insert_one.hpp>
34#include <mongocxx/options/aggregate.hpp>
35#include <mongocxx/options/bulk_write.hpp>
36#include <mongocxx/options/change_stream.hpp>
37#include <mongocxx/options/count.hpp>
38#include <mongocxx/options/delete.hpp>
39#include <mongocxx/options/distinct.hpp>
40#include <mongocxx/options/estimated_document_count.hpp>
41#include <mongocxx/options/find.hpp>
42#include <mongocxx/options/find_one_and_delete.hpp>
43#include <mongocxx/options/find_one_and_replace.hpp>
44#include <mongocxx/options/find_one_and_update.hpp>
45#include <mongocxx/options/index.hpp>
46#include <mongocxx/options/index_view.hpp>
47#include <mongocxx/options/insert.hpp>
48#include <mongocxx/options/replace.hpp>
49#include <mongocxx/options/update.hpp>
50#include <mongocxx/pipeline.hpp>
51#include <mongocxx/read_concern.hpp>
52#include <mongocxx/read_preference.hpp>
53#include <mongocxx/result/bulk_write.hpp>
54#include <mongocxx/result/delete.hpp>
55#include <mongocxx/result/insert_many.hpp>
56#include <mongocxx/result/insert_one.hpp>
57#include <mongocxx/result/replace_one.hpp>
58#include <mongocxx/result/update.hpp>
59#include <mongocxx/write_concern.hpp>
60
61#include <mongocxx/config/prelude.hpp>
62
63namespace mongocxx {
64MONGOCXX_INLINE_NAMESPACE_BEGIN
65
66class client;
67class database;
68
83class MONGOCXX_API collection {
84 //
85 // Utility class supporting the convenience of {} meaning an empty bsoncxx::document.
86 //
87 // Users may not use this class directly.
88 //
89 // In places where driver methods take this class as a parameter, passing {} will
90 // translate to a default-constructed bsoncxx::document::view_or_value,
91 // regardless of other overloads taking other default-constructible types
92 // for that parameter. This class avoids compiler ambiguity with such overloads.
93 //
94 // See collection::update_one for an example of such overloads.
95 //
96 class _empty_doc_tag {
97 _empty_doc_tag() = default;
98 };
99
100 public:
107 collection() noexcept;
108
113
117 collection& operator=(collection&&) noexcept;
118
123
127 collection& operator=(const collection&);
128
133
138 explicit operator bool() const noexcept;
139
161 cursor aggregate(const pipeline& pipeline,
162 const options::aggregate& options = options::aggregate());
163
185 cursor aggregate(const client_session& session,
186 const pipeline& pipeline,
187 const options::aggregate& options = options::aggregate());
191
204 class bulk_write create_bulk_write(const options::bulk_write& options = {});
205
218 class bulk_write create_bulk_write(const client_session& session,
219 const options::bulk_write& options = {});
223
246 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
247 const model::write& write, const options::bulk_write& options = options::bulk_write());
248
271 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
272 const client_session& session,
273 const model::write& write,
274 const options::bulk_write& options = options::bulk_write());
278
302 template <typename container_type>
303 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
304 const container_type& writes, const options::bulk_write& options = options::bulk_write());
305
329 template <typename container_type>
330 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
331 const client_session& session,
332 const container_type& writes,
333 const options::bulk_write& options = options::bulk_write());
337
362 template <typename write_model_iterator_type>
363 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
364 write_model_iterator_type begin,
365 write_model_iterator_type end,
366 const options::bulk_write& options = options::bulk_write());
367
392 template <typename write_model_iterator_type>
393 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
394 const client_session& session,
395 write_model_iterator_type begin,
396 write_model_iterator_type end,
397 const options::bulk_write& options = options::bulk_write());
401
427 const options::count& options = options::count());
428
450 std::int64_t count_documents(const client_session& session,
452 const options::count& options = options::count());
456
479
503 bsoncxx::document::view_or_value index_options = {},
504 options::index_view operation_options = options::index_view{});
505
528 const client_session& session,
530 bsoncxx::document::view_or_value index_options = {},
531 options::index_view operation_options = options::index_view{});
532
536
555 stdx::optional<result::delete_result> delete_many(
558
577 stdx::optional<result::delete_result> delete_many(
578 const client_session& session,
581
585
604 stdx::optional<result::delete_result> delete_one(
607
626 stdx::optional<result::delete_result> delete_one(
627 const client_session& session,
630
634
646
650
655 const options::distinct& options = options::distinct());
656
668
672
678 const options::distinct& options = options::distinct());
679
683
702 void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
703
722 void drop(const client_session& session,
723 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
724
728
749 const options::find& options = options::find());
750
770 cursor find(const client_session& session,
772 const options::find& options = options::find());
773
790 stdx::optional<bsoncxx::document::value> find_one(
792
809 stdx::optional<bsoncxx::document::value> find_one(
810 const client_session& session,
812 const options::find& options = options::find());
813
817
837 stdx::optional<bsoncxx::document::value> find_one_and_delete(
840
860 stdx::optional<bsoncxx::document::value> find_one_and_delete(
861 const client_session& session,
864
868
891 stdx::optional<bsoncxx::document::value> find_one_and_replace(
895
918 stdx::optional<bsoncxx::document::value> find_one_and_replace(
919 const client_session& session,
923
927
950 stdx::optional<bsoncxx::document::value> find_one_and_update(
954
975 stdx::optional<bsoncxx::document::value> find_one_and_update(
977 const pipeline& update,
979
1000 stdx::optional<bsoncxx::document::value> find_one_and_update(
1002 std::initializer_list<_empty_doc_tag> update,
1004
1027 stdx::optional<bsoncxx::document::value> find_one_and_update(
1028 const client_session& session,
1032
1055 stdx::optional<bsoncxx::document::value> find_one_and_update(
1056 const client_session& session,
1058 const pipeline& update,
1060
1083 stdx::optional<bsoncxx::document::value> find_one_and_update(
1084 const client_session& session,
1086 std::initializer_list<_empty_doc_tag> update,
1088
1092
1109 stdx::optional<result::insert_one> insert_one(bsoncxx::document::view_or_value document,
1110 const options::insert& options = {});
1127 stdx::optional<result::insert_one> insert_one(const client_session& session,
1129 const options::insert& options = {});
1133
1159 template <typename container_type>
1160 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1161 const container_type& container, const options::insert& options = options::insert());
1162
1184 template <typename container_type>
1185 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1186 const client_session& session,
1187 const container_type& container,
1188 const options::insert& options = options::insert());
1189
1215 template <typename document_view_iterator_type>
1216 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1217 document_view_iterator_type begin,
1218 document_view_iterator_type end,
1219 const options::insert& options = options::insert());
1220
1242 template <typename document_view_iterator_type>
1243 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1244 const client_session& session,
1245 document_view_iterator_type begin,
1246 document_view_iterator_type end,
1247 const options::insert& options = options::insert());
1251
1264
1277 cursor list_indexes(const client_session& session) const;
1278
1282
1289 stdx::string_view name() const;
1290
1311 bool drop_target_before_rename = false,
1312 const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1313
1335 void rename(const client_session& session,
1337 bool drop_target_before_rename = false,
1338 const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1339
1343
1354
1364
1375
1384
1407 stdx::optional<result::replace_one> replace_one(
1410 const options::replace& options = options::replace{});
1411
1434 stdx::optional<result::replace_one> replace_one(
1435 const client_session& session,
1438 const options::replace& options = options::replace{});
1439
1462 stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1464 const options::update& options = options::update());
1465
1486 stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1487 const pipeline& update,
1488 const options::update& options = options::update());
1489
1510 stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1511 std::initializer_list<_empty_doc_tag> update,
1512 const options::update& options = options::update());
1513
1536 stdx::optional<result::update> update_many(const client_session& session,
1539 const options::update& options = options::update());
1540
1563 stdx::optional<result::update> update_many(const client_session& session,
1565 const pipeline& update,
1566 const options::update& options = options::update());
1567
1590 stdx::optional<result::update> update_many(const client_session& session,
1592 std::initializer_list<_empty_doc_tag> update,
1593 const options::update& options = options::update());
1594
1598
1621 stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1623 const options::update& options = options::update());
1624
1645 stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1646 const pipeline& update,
1647 const options::update& options = options::update());
1648
1669 stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1670 std::initializer_list<_empty_doc_tag> update,
1671 const options::update& options = options::update());
1672
1695 stdx::optional<result::update> update_one(const client_session& session,
1698 const options::update& options = options::update());
1699
1722 stdx::optional<result::update> update_one(const client_session& session,
1724 const pipeline& update,
1725 const options::update& options = options::update());
1726
1749 stdx::optional<result::update> update_one(const client_session& session,
1751 std::initializer_list<_empty_doc_tag> update,
1752 const options::update& options = options::update());
1753
1757
1766
1773
1777
1793
1805 change_stream watch(const client_session& session, const options::change_stream& options = {});
1806
1823 change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
1824
1841 const pipeline& pipe,
1842 const options::change_stream& options = {});
1843
1847
1848 private:
1849 friend class bulk_write;
1850 friend class database;
1851
1852 MONGOCXX_PRIVATE collection(const database& database,
1853 bsoncxx::string::view_or_value collection_name);
1854
1855 MONGOCXX_PRIVATE collection(const database& database, void* collection);
1856
1857 MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
1858 const pipeline& pipeline,
1859 const options::aggregate& options);
1860
1861 MONGOCXX_PRIVATE std::int64_t _count(const client_session* session,
1863 const options::count& options);
1864
1865 MONGOCXX_PRIVATE std::int64_t _count_documents(const client_session* session,
1867 const options::count& options);
1868
1869 MONGOCXX_PRIVATE bsoncxx::document::value _create_index(
1870 const client_session* session,
1873 options::index_view operation_options);
1874
1875 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
1876 const client_session* session,
1878 const options::delete_options& options);
1879
1880 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
1881 const client_session* session,
1883 const options::delete_options& options);
1884
1885 MONGOCXX_PRIVATE cursor _distinct(const client_session* session,
1888 const options::distinct& options);
1889
1890 MONGOCXX_PRIVATE void _drop(
1891 const client_session* session,
1892 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
1893
1894 MONGOCXX_PRIVATE cursor _find(const client_session* session,
1896 const options::find& options);
1897
1898 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one(
1899 const client_session* session,
1901 const options::find& options);
1902
1903 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_delete(
1904 const client_session* session,
1906 const options::find_one_and_delete& options);
1907
1908 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_replace(
1909 const client_session* session,
1912 const options::find_one_and_replace& options);
1913
1914 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_update(
1915 const client_session* session,
1918 const options::find_one_and_update& options);
1919
1920 MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
1921 const client_session* session,
1923 const options::insert& options);
1924
1925 MONGOCXX_PRIVATE void _rename(
1926 const client_session* session,
1928 bool drop_target_before_rename,
1929 const bsoncxx::stdx::optional<class write_concern>& write_concern);
1930
1931 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1932 const client_session* session,
1933 const options::bulk_write& bulk_opts,
1934 const model::replace_one& replace_op);
1935
1936 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1937 const client_session* session,
1940 const options::replace& options);
1941
1942 MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
1943 const client_session* session,
1946 const options::update& options);
1947
1948 MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
1949 const client_session* session,
1952 const options::update& options);
1953
1954 MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
1955 const pipeline& pipe,
1956 const options::change_stream& options);
1957
1958 // Helpers for the insert_many method templates.
1959 class bulk_write _init_insert_many(const options::insert& options,
1960 const client_session* session);
1961
1962 void _insert_many_doc_handler(class bulk_write& writes,
1963 bsoncxx::builder::basic::array& inserted_ids,
1964 bsoncxx::document::view doc) const;
1965
1966 stdx::optional<result::insert_many> _exec_insert_many(
1967 class bulk_write& writes, bsoncxx::builder::basic::array& inserted_ids);
1968
1969 template <typename document_view_iterator_type>
1970 MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
1971 const client_session* session,
1972 document_view_iterator_type begin,
1973 document_view_iterator_type end,
1974 const options::insert& options);
1975
1976 class MONGOCXX_PRIVATE impl;
1977
1978 MONGOCXX_PRIVATE impl& _get_impl();
1979 MONGOCXX_PRIVATE const impl& _get_impl() const;
1980
1981 std::unique_ptr<impl> _impl;
1982};
1983
1984MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1985 const model::write& write, const options::bulk_write& options) {
1986 return create_bulk_write(options).append(write).execute();
1987}
1988
1989MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1990 const client_session& session, const model::write& write, const options::bulk_write& options) {
1991 return create_bulk_write(session, options).append(write).execute();
1992}
1993
1994template <typename container_type>
1995MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1996 const container_type& requests, const options::bulk_write& options) {
1997 return bulk_write(requests.begin(), requests.end(), options);
1998}
1999
2000template <typename container_type>
2001MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2002 const client_session& session,
2003 const container_type& requests,
2004 const options::bulk_write& options) {
2005 return bulk_write(session, requests.begin(), requests.end(), options);
2006}
2007
2008template <typename write_model_iterator_type>
2009MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2010 write_model_iterator_type begin,
2011 write_model_iterator_type end,
2012 const options::bulk_write& options) {
2013 auto writes = create_bulk_write(options);
2014 std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2015 return writes.execute();
2016}
2017
2018template <typename write_model_iterator_type>
2019MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2020 const client_session& session,
2021 write_model_iterator_type begin,
2022 write_model_iterator_type end,
2023 const options::bulk_write& options) {
2024 auto writes = create_bulk_write(session, options);
2025 std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2026 return writes.execute();
2027}
2028
2029template <typename container_type>
2030MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2031 const container_type& container, const options::insert& options) {
2032 return insert_many(container.begin(), container.end(), options);
2033}
2034
2035template <typename container_type>
2036MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2037 const client_session& session,
2038 const container_type& container,
2039 const options::insert& options) {
2040 return insert_many(session, container.begin(), container.end(), options);
2041}
2042
2043template <typename document_view_iterator_type>
2044MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
2045
2046 const client_session* session,
2047 document_view_iterator_type begin,
2048 document_view_iterator_type end,
2049 const options::insert& options) {
2050 bsoncxx::builder::basic::array inserted_ids;
2051 auto writes = _init_insert_many(options, session);
2052 std::for_each(begin, end, [&inserted_ids, &writes, this](bsoncxx::document::view doc) {
2053 _insert_many_doc_handler(writes, inserted_ids, doc);
2054 });
2055 return _exec_insert_many(writes, inserted_ids);
2056}
2057
2058template <typename document_view_iterator_type>
2059MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2060 document_view_iterator_type begin,
2061 document_view_iterator_type end,
2062 const options::insert& options) {
2063 return _insert_many(nullptr, begin, end, options);
2064}
2065
2066template <typename document_view_iterator_type>
2067MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2068 const client_session& session,
2069 document_view_iterator_type begin,
2070 document_view_iterator_type end,
2071 const options::insert& options) {
2072 return _insert_many(&session, begin, end, options);
2073}
2074
2075MONGOCXX_INLINE_NAMESPACE_END
2076} // namespace mongocxx
2077
2078#include <mongocxx/config/postlude.hpp>
A traditional builder-style interface for constructing a BSON array.
Definition array.hpp:35
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:34
A read-only, non-owning view of a BSON document.
Definition view.hpp:33
Class representing a view-or-value variant type for strings.
Definition view_or_value.hpp:36
Class representing a batch of write operations that can be sent to the server as a group.
Definition bulk_write.hpp:43
Class representing a MongoDB change stream.
Definition change_stream.hpp:34
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition client_session.hpp:40
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:83
collection() noexcept
Default constructs a collection object.
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 write_concern(class write_concern wc)
Sets the write_concern for this collection.
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< 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...
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.
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.
change_stream watch(const options::change_stream &options={})
Gets a change stream on this collection with an empty pipeline.
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...
index_view indexes()
Gets an index_view to the collection.
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...
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.
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.
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.
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 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.
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.
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::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.
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.
cursor list_indexes() const
Returns a list of the indexes currently on this collection.
void read_preference(class read_preference rp)
Sets the read_preference for this collection.
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.
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< 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.
change_stream watch(const client_session &session, const options::change_stream &options={})
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
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...
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< 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.
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_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...
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.
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.
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< 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.
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.
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...
void drop(const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops this collection and all its contained documents from the database.
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< 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::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::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.
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.
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
void read_concern(class read_concern rc)
Sets the read_concern for this collection.
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::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.
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.
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.
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< 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.
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::string_view name() const
Returns the name of this collection.
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.
stdx::optional< result::insert_one > insert_one(bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
cursor list_indexes(const client_session &session) const
Returns a list of the indexes currently on this collection.
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:36
Class representing a MongoDB database.
Definition database.hpp:43
Class representing a MongoDB index view.
Definition index_view.hpp:35
Class representing a MongoDB update operation that replaces a single document.
Definition replace_one.hpp:31
Models a single write operation within a mongocxx::bulk_write.
Definition write.hpp:37
Class representing the optional arguments to a MongoDB aggregation operation.
Definition aggregate.hpp:39
Class representing the optional arguments to a MongoDB bulk write.
Definition bulk_write.hpp:31
Class representing MongoDB change stream options.
Definition change_stream.hpp:39
Class representing the optional arguments to mongocxx::collection::count_documents.
Definition count.hpp:37
Class representing the optional arguments to a MongoDB delete operation.
Definition delete.hpp:32
Class representing the optional arguments to a MongoDB distinct command.
Definition distinct.hpp:35
Class representing the optional arguments to mongocxx::collection::estimated_document_count.
Definition estimated_document_count.hpp:33
Class representing the optional arguments to a MongoDB find_and_modify delete operation.
Definition find_one_and_delete.hpp:35
Class representing the optional arguments to a MongoDB find_and_modify replace operation.
Definition find_one_and_replace.hpp:37
Class representing the optional arguments to a MongoDB find_and_modify update operation.
Definition find_one_and_update.hpp:38
Class representing the optional arguments to a MongoDB query.
Definition find.hpp:37
Class representing optional arguments to IndexView operations.
Definition index_view.hpp:31
Class representing the optional arguments to a MongoDB insert operation.
Definition insert.hpp:32
Class representing the optional arguments to a MongoDB replace operation.
Definition replace.hpp:34
Class representing the optional arguments to a MongoDB update operation.
Definition update.hpp:34
Class representing a MongoDB aggregation pipeline.
Definition pipeline.hpp:38
A class to represent the read concern.
Definition read_concern.hpp:54
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:63
Class representing the server-side requirement for reporting the success of a write operation.
Definition write_concern.hpp:56
Top level namespace for the MongoDB C++ driver.
Definition bulk_write.hpp:24