MongoDB C++ Driver current
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/search_index_view.hpp>
60#include <mongocxx/write_concern.hpp>
61
62#include <mongocxx/config/prelude.hpp>
63
64namespace mongocxx {
65inline namespace v_noabi {
66class bulk_write;
67class client_encryption;
68class client;
69class database;
70
85class MONGOCXX_API collection {
86 //
87 // Utility class supporting the convenience of {} meaning an empty bsoncxx::document.
88 //
89 // Users may not use this class directly.
90 //
91 // In places where driver methods take this class as a parameter, passing {} will
92 // translate to a default-constructed bsoncxx::document::view_or_value,
93 // regardless of other overloads taking other default-constructible types
94 // for that parameter. This class avoids compiler ambiguity with such overloads.
95 //
96 // See collection::update_one for an example of such overloads.
97 //
98 class _empty_doc_tag {
99 _empty_doc_tag() = default;
100 };
101
102 public:
109 collection() noexcept;
110
115
119 collection& operator=(collection&&) noexcept;
120
125
129 collection& operator=(const collection&);
130
135
140 explicit operator bool() const noexcept;
141
163 cursor aggregate(const pipeline& pipeline,
164 const options::aggregate& options = options::aggregate());
165
187 cursor aggregate(const client_session& session,
188 const pipeline& pipeline,
189 const options::aggregate& options = options::aggregate());
193
206 class bulk_write create_bulk_write(const options::bulk_write& options = {});
207
220 class bulk_write create_bulk_write(const client_session& session,
221 const options::bulk_write& options = {});
225
248 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
249 const model::write& write, const options::bulk_write& options = options::bulk_write());
250
273 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
274 const client_session& session,
275 const model::write& write,
276 const options::bulk_write& options = options::bulk_write());
280
304 template <typename container_type>
305 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
306 const container_type& writes, const options::bulk_write& options = options::bulk_write());
307
331 template <typename container_type>
332 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
333 const client_session& session,
334 const container_type& writes,
335 const options::bulk_write& options = options::bulk_write());
339
364 template <typename write_model_iterator_type>
365 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
366 write_model_iterator_type begin,
367 write_model_iterator_type end,
368 const options::bulk_write& options = options::bulk_write());
369
394 template <typename write_model_iterator_type>
395 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
396 const client_session& session,
397 write_model_iterator_type begin,
398 write_model_iterator_type end,
399 const options::bulk_write& options = options::bulk_write());
403
428 std::int64_t count_documents(bsoncxx::document::view_or_value filter,
429 const options::count& options = options::count());
430
452 std::int64_t count_documents(const client_session& session,
453 bsoncxx::document::view_or_value filter,
454 const options::count& options = options::count());
458
481
503 bsoncxx::document::value create_index(
504 bsoncxx::document::view_or_value keys,
505 bsoncxx::document::view_or_value index_options = {},
506 options::index_view operation_options = options::index_view{});
507
529 bsoncxx::document::value create_index(
530 const client_session& session,
531 bsoncxx::document::view_or_value keys,
532 bsoncxx::document::view_or_value index_options = {},
533 options::index_view operation_options = options::index_view{});
534
538
557 stdx::optional<result::delete_result> delete_many(
558 bsoncxx::document::view_or_value filter,
560
579 stdx::optional<result::delete_result> delete_many(
580 const client_session& session,
581 bsoncxx::document::view_or_value filter,
583
587
606 stdx::optional<result::delete_result> delete_one(
607 bsoncxx::document::view_or_value filter,
609
628 stdx::optional<result::delete_result> delete_one(
629 const client_session& session,
630 bsoncxx::document::view_or_value filter,
632
636
648
652
655 cursor distinct(bsoncxx::string::view_or_value name,
656 bsoncxx::document::view_or_value filter,
657 const options::distinct& options = options::distinct());
658
670
674
678 bsoncxx::string::view_or_value name,
679 bsoncxx::document::view_or_value filter,
680 const options::distinct& options = options::distinct());
681
685
707 void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {},
708 bsoncxx::document::view_or_value collection_options = {});
709
730 void drop(const client_session& session,
731 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {},
732 bsoncxx::document::view_or_value collection_options = {});
733
737
757 cursor find(bsoncxx::document::view_or_value filter,
758 const options::find& options = options::find());
759
779 cursor find(const client_session& session,
780 bsoncxx::document::view_or_value filter,
781 const options::find& options = options::find());
782
799 stdx::optional<bsoncxx::document::value> find_one(
800 bsoncxx::document::view_or_value filter, const options::find& options = options::find());
801
818 stdx::optional<bsoncxx::document::value> find_one(
819 const client_session& session,
820 bsoncxx::document::view_or_value filter,
821 const options::find& options = options::find());
822
826
846 stdx::optional<bsoncxx::document::value> find_one_and_delete(
847 bsoncxx::document::view_or_value filter,
849
869 stdx::optional<bsoncxx::document::value> find_one_and_delete(
870 const client_session& session,
871 bsoncxx::document::view_or_value filter,
873
877
900 stdx::optional<bsoncxx::document::value> find_one_and_replace(
901 bsoncxx::document::view_or_value filter,
902 bsoncxx::document::view_or_value replacement,
904
927 stdx::optional<bsoncxx::document::value> find_one_and_replace(
928 const client_session& session,
929 bsoncxx::document::view_or_value filter,
930 bsoncxx::document::view_or_value replacement,
932
936
959 stdx::optional<bsoncxx::document::value> find_one_and_update(
960 bsoncxx::document::view_or_value filter,
961 bsoncxx::document::view_or_value update,
963
984 stdx::optional<bsoncxx::document::value> find_one_and_update(
985 bsoncxx::document::view_or_value filter,
986 const pipeline& update,
988
1009 stdx::optional<bsoncxx::document::value> find_one_and_update(
1010 bsoncxx::document::view_or_value filter,
1011 std::initializer_list<_empty_doc_tag> update,
1013
1036 stdx::optional<bsoncxx::document::value> find_one_and_update(
1037 const client_session& session,
1038 bsoncxx::document::view_or_value filter,
1039 bsoncxx::document::view_or_value update,
1041
1064 stdx::optional<bsoncxx::document::value> find_one_and_update(
1065 const client_session& session,
1066 bsoncxx::document::view_or_value filter,
1067 const pipeline& update,
1069
1092 stdx::optional<bsoncxx::document::value> find_one_and_update(
1093 const client_session& session,
1094 bsoncxx::document::view_or_value filter,
1095 std::initializer_list<_empty_doc_tag> update,
1097
1101
1118 stdx::optional<result::insert_one> insert_one(bsoncxx::document::view_or_value document,
1119 const options::insert& options = {});
1136 stdx::optional<result::insert_one> insert_one(const client_session& session,
1137 bsoncxx::document::view_or_value document,
1138 const options::insert& options = {});
1142
1168 template <typename container_type>
1169 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1170 const container_type& container, const options::insert& options = options::insert());
1171
1193 template <typename container_type>
1194 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1195 const client_session& session,
1196 const container_type& container,
1197 const options::insert& options = options::insert());
1198
1224 template <typename document_view_iterator_type>
1225 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1226 document_view_iterator_type begin,
1227 document_view_iterator_type end,
1228 const options::insert& options = options::insert());
1229
1251 template <typename document_view_iterator_type>
1252 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1253 const client_session& session,
1254 document_view_iterator_type begin,
1255 document_view_iterator_type end,
1256 const options::insert& options = options::insert());
1260
1273
1286 cursor list_indexes(const client_session& session) const;
1287
1291
1298 stdx::string_view name() const;
1299
1319 void rename(bsoncxx::string::view_or_value new_name,
1320 bool drop_target_before_rename = false,
1321 const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1322
1344 void rename(const client_session& session,
1345 bsoncxx::string::view_or_value new_name,
1346 bool drop_target_before_rename = false,
1347 const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1348
1352
1363
1373
1384
1393
1416 stdx::optional<result::replace_one> replace_one(
1417 bsoncxx::document::view_or_value filter,
1418 bsoncxx::document::view_or_value replacement,
1419 const options::replace& options = options::replace{});
1420
1443 stdx::optional<result::replace_one> replace_one(
1444 const client_session& session,
1445 bsoncxx::document::view_or_value filter,
1446 bsoncxx::document::view_or_value replacement,
1447 const options::replace& options = options::replace{});
1448
1471 stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1472 bsoncxx::document::view_or_value update,
1473 const options::update& options = options::update());
1474
1495 stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1496 const pipeline& update,
1497 const options::update& options = options::update());
1498
1519 stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1520 std::initializer_list<_empty_doc_tag> update,
1521 const options::update& options = options::update());
1522
1545 stdx::optional<result::update> update_many(const client_session& session,
1546 bsoncxx::document::view_or_value filter,
1547 bsoncxx::document::view_or_value update,
1548 const options::update& options = options::update());
1549
1572 stdx::optional<result::update> update_many(const client_session& session,
1573 bsoncxx::document::view_or_value filter,
1574 const pipeline& update,
1575 const options::update& options = options::update());
1576
1599 stdx::optional<result::update> update_many(const client_session& session,
1600 bsoncxx::document::view_or_value filter,
1601 std::initializer_list<_empty_doc_tag> update,
1602 const options::update& options = options::update());
1603
1607
1630 stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1631 bsoncxx::document::view_or_value update,
1632 const options::update& options = options::update());
1633
1654 stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1655 const pipeline& update,
1656 const options::update& options = options::update());
1657
1678 stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1679 std::initializer_list<_empty_doc_tag> update,
1680 const options::update& options = options::update());
1681
1704 stdx::optional<result::update> update_one(const client_session& session,
1705 bsoncxx::document::view_or_value filter,
1706 bsoncxx::document::view_or_value update,
1707 const options::update& options = options::update());
1708
1731 stdx::optional<result::update> update_one(const client_session& session,
1732 bsoncxx::document::view_or_value filter,
1733 const pipeline& update,
1734 const options::update& options = options::update());
1735
1758 stdx::optional<result::update> update_one(const client_session& session,
1759 bsoncxx::document::view_or_value filter,
1760 std::initializer_list<_empty_doc_tag> update,
1761 const options::update& options = options::update());
1762
1766
1775
1782
1786
1802
1814 change_stream watch(const client_session& session, const options::change_stream& options = {});
1815
1832 change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
1833
1850 const pipeline& pipe,
1851 const options::change_stream& options = {});
1852
1856
1860
1861 private:
1862 friend class bulk_write;
1863 friend class client_encryption;
1864 friend class database;
1865
1866 MONGOCXX_PRIVATE collection(const database& database,
1867 bsoncxx::string::view_or_value collection_name);
1868
1869 MONGOCXX_PRIVATE collection(const database& database, void* collection);
1870
1871 MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
1872 const pipeline& pipeline,
1873 const options::aggregate& options);
1874
1875 MONGOCXX_PRIVATE std::int64_t _count(const client_session* session,
1876 bsoncxx::document::view_or_value filter,
1877 const options::count& options);
1878
1879 MONGOCXX_PRIVATE std::int64_t _count_documents(const client_session* session,
1880 bsoncxx::document::view_or_value filter,
1881 const options::count& options);
1882
1883 MONGOCXX_PRIVATE bsoncxx::document::value _create_index(
1884 const client_session* session,
1885 bsoncxx::document::view_or_value keys,
1886 bsoncxx::document::view_or_value index_options,
1887 options::index_view operation_options);
1888
1889 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
1890 const client_session* session,
1891 bsoncxx::document::view_or_value filter,
1892 const options::delete_options& options);
1893
1894 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
1895 const client_session* session,
1896 bsoncxx::document::view_or_value filter,
1897 const options::delete_options& options);
1898
1899 MONGOCXX_PRIVATE cursor _distinct(const client_session* session,
1900 bsoncxx::string::view_or_value name,
1901 bsoncxx::document::view_or_value filter,
1902 const options::distinct& options);
1903
1904 MONGOCXX_PRIVATE void _drop(
1905 const client_session* session,
1906 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern,
1907 bsoncxx::document::view_or_value collection_options);
1908
1909 MONGOCXX_PRIVATE cursor _find(const client_session* session,
1910 bsoncxx::document::view_or_value filter,
1911 const options::find& options);
1912
1913 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one(
1914 const client_session* session,
1915 bsoncxx::document::view_or_value filter,
1916 const options::find& options);
1917
1918 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_delete(
1919 const client_session* session,
1920 bsoncxx::document::view_or_value filter,
1921 const options::find_one_and_delete& options);
1922
1923 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_replace(
1924 const client_session* session,
1925 bsoncxx::document::view_or_value filter,
1926 bsoncxx::document::view_or_value replacement,
1927 const options::find_one_and_replace& options);
1928
1929 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_update(
1930 const client_session* session,
1931 bsoncxx::document::view_or_value filter,
1932 bsoncxx::document::view_or_value update,
1933 const options::find_one_and_update& options);
1934
1935 MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
1936 const client_session* session,
1937 bsoncxx::document::view_or_value document,
1938 const options::insert& options);
1939
1940 MONGOCXX_PRIVATE void _rename(
1941 const client_session* session,
1942 bsoncxx::string::view_or_value new_name,
1943 bool drop_target_before_rename,
1944 const bsoncxx::stdx::optional<class write_concern>& write_concern);
1945
1946 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1947 const client_session* session,
1948 const options::bulk_write& bulk_opts,
1949 const model::replace_one& replace_op);
1950
1951 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1952 const client_session* session,
1953 bsoncxx::document::view_or_value filter,
1954 bsoncxx::document::view_or_value replacement,
1955 const options::replace& options);
1956
1957 MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
1958 const client_session* session,
1959 bsoncxx::document::view_or_value filter,
1960 bsoncxx::document::view_or_value update,
1961 const options::update& options);
1962
1963 MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
1964 const client_session* session,
1965 bsoncxx::document::view_or_value filter,
1966 bsoncxx::document::view_or_value update,
1967 const options::update& options);
1968
1969 MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
1970 const pipeline& pipe,
1971 const options::change_stream& options);
1972
1973 // Helpers for the insert_many method templates.
1974 class bulk_write _init_insert_many(const options::insert& options,
1975 const client_session* session);
1976
1977 void _insert_many_doc_handler(class bulk_write& writes,
1978 bsoncxx::builder::basic::array& inserted_ids,
1979 bsoncxx::document::view doc) const;
1980
1981 stdx::optional<result::insert_many> _exec_insert_many(
1982 class bulk_write& writes, bsoncxx::builder::basic::array& inserted_ids);
1983
1984 template <typename document_view_iterator_type>
1985 MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
1986 const client_session* session,
1987 document_view_iterator_type begin,
1988 document_view_iterator_type end,
1989 const options::insert& options);
1990
1991 class MONGOCXX_PRIVATE impl;
1992
1993 MONGOCXX_PRIVATE impl& _get_impl();
1994 MONGOCXX_PRIVATE const impl& _get_impl() const;
1995
1996 std::unique_ptr<impl> _impl;
1997};
1998
1999MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
2000 const model::write& write, const options::bulk_write& options) {
2001 return create_bulk_write(options).append(write).execute();
2002}
2003
2004MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
2005 const client_session& session, const model::write& write, const options::bulk_write& options) {
2006 return create_bulk_write(session, options).append(write).execute();
2007}
2008
2009template <typename container_type>
2010MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2011 const container_type& requests, const options::bulk_write& options) {
2012 return bulk_write(requests.begin(), requests.end(), options);
2013}
2014
2015template <typename container_type>
2016MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2017 const client_session& session,
2018 const container_type& requests,
2019 const options::bulk_write& options) {
2020 return bulk_write(session, requests.begin(), requests.end(), options);
2021}
2022
2023template <typename write_model_iterator_type>
2024MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2025 write_model_iterator_type begin,
2026 write_model_iterator_type end,
2027 const options::bulk_write& options) {
2028 auto writes = create_bulk_write(options);
2029 std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2030 return writes.execute();
2031}
2032
2033template <typename write_model_iterator_type>
2034MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2035 const client_session& session,
2036 write_model_iterator_type begin,
2037 write_model_iterator_type end,
2038 const options::bulk_write& options) {
2039 auto writes = create_bulk_write(session, options);
2040 std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2041 return writes.execute();
2042}
2043
2044template <typename container_type>
2045MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2046 const container_type& container, const options::insert& options) {
2047 return insert_many(container.begin(), container.end(), options);
2048}
2049
2050template <typename container_type>
2051MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2052 const client_session& session,
2053 const container_type& container,
2054 const options::insert& options) {
2055 return insert_many(session, container.begin(), container.end(), options);
2056}
2057
2058template <typename document_view_iterator_type>
2059MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
2060
2061 const client_session* session,
2062 document_view_iterator_type begin,
2063 document_view_iterator_type end,
2064 const options::insert& options) {
2065 bsoncxx::builder::basic::array inserted_ids;
2066 auto writes = _init_insert_many(options, session);
2067 std::for_each(begin, end, [&inserted_ids, &writes, this](bsoncxx::document::view doc) {
2068 _insert_many_doc_handler(writes, inserted_ids, doc);
2069 });
2070 return _exec_insert_many(writes, inserted_ids);
2071}
2072
2073template <typename document_view_iterator_type>
2074MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2075 document_view_iterator_type begin,
2076 document_view_iterator_type end,
2077 const options::insert& options) {
2078 return _insert_many(nullptr, begin, end, options);
2079}
2080
2081template <typename document_view_iterator_type>
2082MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2083 const client_session& session,
2084 document_view_iterator_type begin,
2085 document_view_iterator_type end,
2086 const options::insert& options) {
2087 return _insert_many(&session, begin, end, options);
2088}
2089
2090} // namespace v_noabi
2091} // namespace mongocxx
2092
2093#include <mongocxx/config/postlude.hpp>
A traditional builder-style interface for constructing a BSON array.
Definition array.hpp:35
Class representing a batch of write operations that can be sent to the server as a group.
Definition bulk_write.hpp:42
Class representing a MongoDB change stream.
Definition change_stream.hpp:33
Class supporting operations for MongoDB Client-Side Field Level Encryption.
Definition client_encryption.hpp:38
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:85
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.
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...
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.
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.
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.
search_index_view search_indexes()
Gets a search_index_view to the 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.
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::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.
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< 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.
void drop(const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={}, bsoncxx::document::view_or_value collection_options={})
Drops this collection and all its contained documents from the database.
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.
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(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, 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(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::string_view name() const
Returns the name of 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.
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(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.
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.
change_stream watch(const client_session &session, const options::change_stream &options={})
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...
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< 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.
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(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_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.
cursor list_indexes() const
Returns a list of the indexes currently on 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...
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
void write_concern(class write_concern wc)
Sets the write_concern for 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< 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...
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< 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.
void read_concern(class read_concern rc)
Sets the read_concern for 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.
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...
index_view indexes()
Gets an index_view to the collection.
void read_preference(class read_preference rp)
Sets the read_preference for 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::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::insert_one > insert_one(bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
collection() noexcept
Default constructs a collection object.
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...
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.
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.
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.
void drop(const client_session &session, const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={}, bsoncxx::document::view_or_value collection_options={})
Drops this collection and all its contained documents from the database.
cursor list_indexes(const client_session &session) const
Returns a list of the indexes currently on this 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(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.
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::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.
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:44
Class representing a MongoDB index view.
Definition index_view.hpp:34
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:38
Class representing the optional arguments to mongocxx::collection::count_documents.
Definition count.hpp:36
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:32
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:37
A class to represent the read concern.
Definition read_concern.hpp:57
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:67
Class representing a MongoDB search index view.
Definition search_index_view.hpp:19
Class representing the server-side requirement for reporting the success of a write operation.
Definition write_concern.hpp:59
The top-level namespace for mongocxx library entities.
Definition bulk_write.hpp:24