MongoDB C++ Driver  mongocxx-3.8.1
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
63 namespace mongocxx {
64 MONGOCXX_INLINE_NAMESPACE_BEGIN
65 
66 class client;
67 class database;
68 class client_encryption;
69 
84 class MONGOCXX_API collection {
85  //
86  // Utility class supporting the convenience of {} meaning an empty bsoncxx::document.
87  //
88  // Users may not use this class directly.
89  //
90  // In places where driver methods take this class as a parameter, passing {} will
91  // translate to a default-constructed bsoncxx::document::view_or_value,
92  // regardless of other overloads taking other default-constructible types
93  // for that parameter. This class avoids compiler ambiguity with such overloads.
94  //
95  // See collection::update_one for an example of such overloads.
96  //
97  class _empty_doc_tag {
98  _empty_doc_tag() = default;
99  };
100 
101  public:
108  collection() noexcept;
109 
113  collection(collection&&) noexcept;
114 
118  collection& operator=(collection&&) noexcept;
119 
124 
128  collection& operator=(const collection&);
129 
134 
139  explicit operator bool() const noexcept;
140 
162  cursor aggregate(const pipeline& pipeline,
163  const options::aggregate& options = options::aggregate());
164 
186  cursor aggregate(const client_session& session,
187  const pipeline& pipeline,
188  const options::aggregate& options = options::aggregate());
192 
205  class bulk_write create_bulk_write(const options::bulk_write& options = {});
206 
219  class bulk_write create_bulk_write(const client_session& session,
220  const options::bulk_write& options = {});
224 
247  MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
248  const model::write& write, const options::bulk_write& options = options::bulk_write());
249 
272  MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
273  const client_session& session,
274  const model::write& write,
275  const options::bulk_write& options = options::bulk_write());
279 
303  template <typename container_type>
304  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
305  const container_type& writes, const options::bulk_write& options = options::bulk_write());
306 
330  template <typename container_type>
331  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
332  const client_session& session,
333  const container_type& writes,
334  const options::bulk_write& options = options::bulk_write());
338 
363  template <typename write_model_iterator_type>
364  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
365  write_model_iterator_type begin,
366  write_model_iterator_type end,
367  const options::bulk_write& options = options::bulk_write());
368 
393  template <typename write_model_iterator_type>
394  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
395  const client_session& session,
396  write_model_iterator_type begin,
397  write_model_iterator_type end,
398  const options::bulk_write& options = options::bulk_write());
402 
428  const options::count& options = options::count());
429 
451  std::int64_t count_documents(const client_session& session,
453  const options::count& options = options::count());
457 
480 
504  bsoncxx::document::view_or_value index_options = {},
505  options::index_view operation_options = options::index_view{});
506 
529  const client_session& session,
531  bsoncxx::document::view_or_value index_options = {},
532  options::index_view operation_options = options::index_view{});
533 
537 
556  stdx::optional<result::delete_result> delete_many(
559 
578  stdx::optional<result::delete_result> delete_many(
579  const client_session& session,
582 
586 
605  stdx::optional<result::delete_result> delete_one(
608 
627  stdx::optional<result::delete_result> delete_one(
628  const client_session& session,
631 
635 
647 
651 
656  const options::distinct& options = options::distinct());
657 
669 
673 
679  const options::distinct& options = options::distinct());
680 
684 
703  void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {},
704  bsoncxx::document::view_or_value collection_options = {});
705 
724  void drop(const client_session& session,
725  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {},
726  bsoncxx::document::view_or_value collection_options = {});
727 
731 
752  const options::find& options = options::find());
753 
773  cursor find(const client_session& session,
775  const options::find& options = options::find());
776 
793  stdx::optional<bsoncxx::document::value> find_one(
795 
812  stdx::optional<bsoncxx::document::value> find_one(
813  const client_session& session,
815  const options::find& options = options::find());
816 
820 
840  stdx::optional<bsoncxx::document::value> find_one_and_delete(
843 
863  stdx::optional<bsoncxx::document::value> find_one_and_delete(
864  const client_session& session,
867 
871 
894  stdx::optional<bsoncxx::document::value> find_one_and_replace(
898 
921  stdx::optional<bsoncxx::document::value> find_one_and_replace(
922  const client_session& session,
926 
930 
953  stdx::optional<bsoncxx::document::value> find_one_and_update(
957 
978  stdx::optional<bsoncxx::document::value> find_one_and_update(
980  const pipeline& update,
982 
1003  stdx::optional<bsoncxx::document::value> find_one_and_update(
1005  std::initializer_list<_empty_doc_tag> update,
1007 
1030  stdx::optional<bsoncxx::document::value> find_one_and_update(
1031  const client_session& session,
1035 
1058  stdx::optional<bsoncxx::document::value> find_one_and_update(
1059  const client_session& session,
1061  const pipeline& update,
1063 
1086  stdx::optional<bsoncxx::document::value> find_one_and_update(
1087  const client_session& session,
1089  std::initializer_list<_empty_doc_tag> update,
1091 
1095 
1112  stdx::optional<result::insert_one> insert_one(bsoncxx::document::view_or_value document,
1113  const options::insert& options = {});
1130  stdx::optional<result::insert_one> insert_one(const client_session& session,
1132  const options::insert& options = {});
1136 
1162  template <typename container_type>
1163  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1164  const container_type& container, const options::insert& options = options::insert());
1165 
1187  template <typename container_type>
1188  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1189  const client_session& session,
1190  const container_type& container,
1191  const options::insert& options = options::insert());
1192 
1218  template <typename document_view_iterator_type>
1219  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1220  document_view_iterator_type begin,
1221  document_view_iterator_type end,
1222  const options::insert& options = options::insert());
1223 
1245  template <typename document_view_iterator_type>
1246  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1247  const client_session& session,
1248  document_view_iterator_type begin,
1249  document_view_iterator_type end,
1250  const options::insert& options = options::insert());
1254 
1267 
1280  cursor list_indexes(const client_session& session) const;
1281 
1285 
1292  stdx::string_view name() const;
1293 
1314  bool drop_target_before_rename = false,
1315  const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1316 
1338  void rename(const client_session& session,
1340  bool drop_target_before_rename = false,
1341  const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1342 
1346 
1356  void read_concern(class read_concern rc);
1357 
1366  class read_concern read_concern() const;
1367 
1378 
1386  class read_preference read_preference() const;
1387 
1410  stdx::optional<result::replace_one> replace_one(
1413  const options::replace& options = options::replace{});
1414 
1437  stdx::optional<result::replace_one> replace_one(
1438  const client_session& session,
1441  const options::replace& options = options::replace{});
1442 
1465  stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1467  const options::update& options = options::update());
1468 
1489  stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1490  const pipeline& update,
1491  const options::update& options = options::update());
1492 
1513  stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1514  std::initializer_list<_empty_doc_tag> update,
1515  const options::update& options = options::update());
1516 
1539  stdx::optional<result::update> update_many(const client_session& session,
1542  const options::update& options = options::update());
1543 
1566  stdx::optional<result::update> update_many(const client_session& session,
1568  const pipeline& update,
1569  const options::update& options = options::update());
1570 
1593  stdx::optional<result::update> update_many(const client_session& session,
1595  std::initializer_list<_empty_doc_tag> update,
1596  const options::update& options = options::update());
1597 
1601 
1624  stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1626  const options::update& options = options::update());
1627 
1648  stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1649  const pipeline& update,
1650  const options::update& options = options::update());
1651 
1672  stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1673  std::initializer_list<_empty_doc_tag> update,
1674  const options::update& options = options::update());
1675 
1698  stdx::optional<result::update> update_one(const client_session& session,
1701  const options::update& options = options::update());
1702 
1725  stdx::optional<result::update> update_one(const client_session& session,
1727  const pipeline& update,
1728  const options::update& options = options::update());
1729 
1752  stdx::optional<result::update> update_one(const client_session& session,
1754  std::initializer_list<_empty_doc_tag> update,
1755  const options::update& options = options::update());
1756 
1760 
1769 
1775  class write_concern write_concern() const;
1776 
1780 
1796 
1808  change_stream watch(const client_session& session, const options::change_stream& options = {});
1809 
1826  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
1827 
1844  const pipeline& pipe,
1845  const options::change_stream& options = {});
1846 
1850 
1851  private:
1852  friend mongocxx::bulk_write;
1853  friend mongocxx::database;
1855 
1856  MONGOCXX_PRIVATE collection(const database& database,
1857  bsoncxx::string::view_or_value collection_name);
1858 
1859  MONGOCXX_PRIVATE collection(const database& database, void* collection);
1860 
1861  MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
1862  const pipeline& pipeline,
1863  const options::aggregate& options);
1864 
1865  MONGOCXX_PRIVATE std::int64_t _count(const client_session* session,
1867  const options::count& options);
1868 
1869  MONGOCXX_PRIVATE std::int64_t _count_documents(const client_session* session,
1871  const options::count& options);
1872 
1873  MONGOCXX_PRIVATE bsoncxx::document::value _create_index(
1874  const client_session* session,
1876  bsoncxx::document::view_or_value index_options,
1877  options::index_view operation_options);
1878 
1879  MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
1880  const client_session* session,
1882  const options::delete_options& options);
1883 
1884  MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
1885  const client_session* session,
1887  const options::delete_options& options);
1888 
1889  MONGOCXX_PRIVATE cursor _distinct(const client_session* session,
1892  const options::distinct& options);
1893 
1894  MONGOCXX_PRIVATE void _drop(
1895  const client_session* session,
1896  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern,
1897  bsoncxx::document::view_or_value collection_options);
1898 
1899  MONGOCXX_PRIVATE cursor _find(const client_session* session,
1901  const options::find& options);
1902 
1903  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one(
1904  const client_session* session,
1906  const options::find& options);
1907 
1908  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_delete(
1909  const client_session* session,
1911  const options::find_one_and_delete& options);
1912 
1913  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_replace(
1914  const client_session* session,
1917  const options::find_one_and_replace& options);
1918 
1919  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_update(
1920  const client_session* session,
1923  const options::find_one_and_update& options);
1924 
1925  MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
1926  const client_session* session,
1928  const options::insert& options);
1929 
1930  MONGOCXX_PRIVATE void _rename(
1931  const client_session* session,
1933  bool drop_target_before_rename,
1934  const bsoncxx::stdx::optional<class write_concern>& write_concern);
1935 
1936  MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1937  const client_session* session,
1938  const options::bulk_write& bulk_opts,
1939  const model::replace_one& replace_op);
1940 
1941  MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1942  const client_session* session,
1945  const options::replace& options);
1946 
1947  MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
1948  const client_session* session,
1951  const options::update& options);
1952 
1953  MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
1954  const client_session* session,
1957  const options::update& options);
1958 
1959  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
1960  const pipeline& pipe,
1961  const options::change_stream& options);
1962 
1963  // Helpers for the insert_many method templates.
1964  class bulk_write _init_insert_many(const options::insert& options,
1965  const client_session* session);
1966 
1967  void _insert_many_doc_handler(class bulk_write& writes,
1968  bsoncxx::builder::basic::array& inserted_ids,
1969  bsoncxx::document::view doc) const;
1970 
1971  stdx::optional<result::insert_many> _exec_insert_many(
1972  class bulk_write& writes, bsoncxx::builder::basic::array& inserted_ids);
1973 
1974  template <typename document_view_iterator_type>
1975  MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
1976  const client_session* session,
1977  document_view_iterator_type begin,
1978  document_view_iterator_type end,
1979  const options::insert& options);
1980 
1981  class MONGOCXX_PRIVATE impl;
1982 
1983  MONGOCXX_PRIVATE impl& _get_impl();
1984  MONGOCXX_PRIVATE const impl& _get_impl() const;
1985 
1986  std::unique_ptr<impl> _impl;
1987 };
1988 
1989 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1990  const model::write& write, const options::bulk_write& options) {
1991  return create_bulk_write(options).append(write).execute();
1992 }
1993 
1994 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1995  const client_session& session, const model::write& write, const options::bulk_write& options) {
1996  return create_bulk_write(session, options).append(write).execute();
1997 }
1998 
1999 template <typename container_type>
2000 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2001  const container_type& requests, const options::bulk_write& options) {
2002  return bulk_write(requests.begin(), requests.end(), options);
2003 }
2004 
2005 template <typename container_type>
2006 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2007  const client_session& session,
2008  const container_type& requests,
2009  const options::bulk_write& options) {
2010  return bulk_write(session, requests.begin(), requests.end(), options);
2011 }
2012 
2013 template <typename write_model_iterator_type>
2014 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2015  write_model_iterator_type begin,
2016  write_model_iterator_type end,
2017  const options::bulk_write& options) {
2018  auto writes = create_bulk_write(options);
2019  std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2020  return writes.execute();
2021 }
2022 
2023 template <typename write_model_iterator_type>
2024 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2025  const client_session& session,
2026  write_model_iterator_type begin,
2027  write_model_iterator_type end,
2028  const options::bulk_write& options) {
2029  auto writes = create_bulk_write(session, options);
2030  std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2031  return writes.execute();
2032 }
2033 
2034 template <typename container_type>
2035 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2036  const container_type& container, const options::insert& options) {
2037  return insert_many(container.begin(), container.end(), options);
2038 }
2039 
2040 template <typename container_type>
2041 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2042  const client_session& session,
2043  const container_type& container,
2044  const options::insert& options) {
2045  return insert_many(session, container.begin(), container.end(), options);
2046 }
2047 
2048 template <typename document_view_iterator_type>
2049 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
2050 
2051  const client_session* session,
2052  document_view_iterator_type begin,
2053  document_view_iterator_type end,
2054  const options::insert& options) {
2055  bsoncxx::builder::basic::array inserted_ids;
2056  auto writes = _init_insert_many(options, session);
2057  std::for_each(begin, end, [&inserted_ids, &writes, this](bsoncxx::document::view doc) {
2058  _insert_many_doc_handler(writes, inserted_ids, doc);
2059  });
2060  return _exec_insert_many(writes, inserted_ids);
2061 }
2062 
2063 template <typename document_view_iterator_type>
2064 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2065  document_view_iterator_type begin,
2066  document_view_iterator_type end,
2067  const options::insert& options) {
2068  return _insert_many(nullptr, begin, end, options);
2069 }
2070 
2071 template <typename document_view_iterator_type>
2072 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2073  const client_session& session,
2074  document_view_iterator_type begin,
2075  document_view_iterator_type end,
2076  const options::insert& options) {
2077  return _insert_many(&session, begin, end, options);
2078 }
2079 
2080 MONGOCXX_INLINE_NAMESPACE_END
2081 } // namespace mongocxx
2082 
2083 #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
Class supporting operations for MongoDB Client-Side Field Level Encryption.
Definition: client_encryption.hpp:39
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:84
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...
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< 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::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.
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, bsoncxx::document::view_or_value 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={}, bsoncxx::document::view_or_value collection_options={})
Drops this collection and all its contained documents from the database.
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.
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 options::change_stream &options={})
Gets a change stream on this collection with an empty pipeline.
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.
index_view indexes()
Gets an index_view to 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< result::insert_many > insert_many(const container_type &container, const options::insert &options=options::insert())
Inserts multiple documents into the collection.
Definition: collection.hpp:2035
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::bulk_write > bulk_write(const container_type &writes, const options::bulk_write &options=options::bulk_write())
Sends a container of writes to the server as a bulk write operation.
Definition: collection.hpp:2000
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...
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< 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::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::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.
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_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...
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.
change_stream watch(const client_session &session, const options::change_stream &options={})
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::insert_one > insert_one(bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into 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.
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::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.
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.
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.
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.
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 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< 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(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.
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_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::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< 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...
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::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, const pipeline &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:1989
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.
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< 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< 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.
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_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< 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< 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...
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:44
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