MongoDB C++ Driver  mongocxx-3.6.4
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 
83 class 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 
112  collection(collection&&) noexcept;
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 
417  const options::count& options = options::count());
418 
433  std::int64_t count_documents(const client_session& session,
435  const options::count& options = options::count());
439 
457 
481  bsoncxx::document::view_or_value index_options = {},
482  options::index_view operation_options = options::index_view{});
483 
506  const client_session& session,
508  bsoncxx::document::view_or_value index_options = {},
509  options::index_view operation_options = options::index_view{});
510 
514 
533  stdx::optional<result::delete_result> delete_many(
536 
555  stdx::optional<result::delete_result> delete_many(
556  const client_session& session,
559 
563 
582  stdx::optional<result::delete_result> delete_one(
585 
604  stdx::optional<result::delete_result> delete_one(
605  const client_session& session,
608 
612 
624 
628 
633  const options::distinct& options = options::distinct());
634 
646 
650 
656  const options::distinct& options = options::distinct());
657 
661 
680  void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
681 
700  void drop(const client_session& session,
701  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
702 
706 
727  const options::find& options = options::find());
728 
748  cursor find(const client_session& session,
750  const options::find& options = options::find());
751 
768  stdx::optional<bsoncxx::document::value> find_one(
770 
787  stdx::optional<bsoncxx::document::value> find_one(
788  const client_session& session,
790  const options::find& options = options::find());
791 
795 
815  stdx::optional<bsoncxx::document::value> find_one_and_delete(
818 
838  stdx::optional<bsoncxx::document::value> find_one_and_delete(
839  const client_session& session,
842 
846 
869  stdx::optional<bsoncxx::document::value> find_one_and_replace(
873 
896  stdx::optional<bsoncxx::document::value> find_one_and_replace(
897  const client_session& session,
901 
905 
928  stdx::optional<bsoncxx::document::value> find_one_and_update(
932 
953  stdx::optional<bsoncxx::document::value> find_one_and_update(
955  const pipeline& update,
957 
978  stdx::optional<bsoncxx::document::value> find_one_and_update(
980  std::initializer_list<_empty_doc_tag> update,
982 
1005  stdx::optional<bsoncxx::document::value> find_one_and_update(
1006  const client_session& session,
1010 
1033  stdx::optional<bsoncxx::document::value> find_one_and_update(
1034  const client_session& session,
1036  const pipeline& update,
1038 
1061  stdx::optional<bsoncxx::document::value> find_one_and_update(
1062  const client_session& session,
1064  std::initializer_list<_empty_doc_tag> update,
1066 
1070 
1087  stdx::optional<result::insert_one> insert_one(bsoncxx::document::view_or_value document,
1088  const options::insert& options = {});
1105  stdx::optional<result::insert_one> insert_one(const client_session& session,
1107  const options::insert& options = {});
1111 
1137  template <typename container_type>
1138  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1139  const container_type& container, const options::insert& options = options::insert());
1140 
1162  template <typename container_type>
1163  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1164  const client_session& session,
1165  const container_type& container,
1166  const options::insert& options = options::insert());
1167 
1193  template <typename document_view_iterator_type>
1194  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1195  document_view_iterator_type begin,
1196  document_view_iterator_type end,
1197  const options::insert& options = options::insert());
1198 
1220  template <typename document_view_iterator_type>
1221  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1222  const client_session& session,
1223  document_view_iterator_type begin,
1224  document_view_iterator_type end,
1225  const options::insert& options = options::insert());
1229 
1242 
1255  cursor list_indexes(const client_session& session) const;
1256 
1260 
1267  stdx::string_view name() const;
1268 
1289  bool drop_target_before_rename = false,
1290  const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1291 
1313  void rename(const client_session& session,
1315  bool drop_target_before_rename = false,
1316  const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1317 
1321 
1331  void read_concern(class read_concern rc);
1332 
1341  class read_concern read_concern() const;
1342 
1353 
1361  class read_preference read_preference() const;
1362 
1385  stdx::optional<result::replace_one> replace_one(
1388  const options::replace& options = options::replace{});
1389 
1412  stdx::optional<result::replace_one> replace_one(
1413  const client_session& session,
1416  const options::replace& options = options::replace{});
1417 
1440  stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1442  const options::update& options = options::update());
1443 
1464  stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1465  const pipeline& update,
1466  const options::update& options = options::update());
1467 
1488  stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1489  std::initializer_list<_empty_doc_tag> update,
1490  const options::update& options = options::update());
1491 
1514  stdx::optional<result::update> update_many(const client_session& session,
1517  const options::update& options = options::update());
1518 
1541  stdx::optional<result::update> update_many(const client_session& session,
1543  const pipeline& update,
1544  const options::update& options = options::update());
1545 
1568  stdx::optional<result::update> update_many(const client_session& session,
1570  std::initializer_list<_empty_doc_tag> update,
1571  const options::update& options = options::update());
1572 
1576 
1599  stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1601  const options::update& options = options::update());
1602 
1623  stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1624  const pipeline& update,
1625  const options::update& options = options::update());
1626 
1647  stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1648  std::initializer_list<_empty_doc_tag> update,
1649  const options::update& options = options::update());
1650 
1673  stdx::optional<result::update> update_one(const client_session& session,
1676  const options::update& options = options::update());
1677 
1700  stdx::optional<result::update> update_one(const client_session& session,
1702  const pipeline& update,
1703  const options::update& options = options::update());
1704 
1727  stdx::optional<result::update> update_one(const client_session& session,
1729  std::initializer_list<_empty_doc_tag> update,
1730  const options::update& options = options::update());
1731 
1735 
1744 
1750  class write_concern write_concern() const;
1751 
1755 
1771 
1783  change_stream watch(const client_session& session, const options::change_stream& options = {});
1784 
1801  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
1802 
1819  const pipeline& pipe,
1820  const options::change_stream& options = {});
1821 
1825 
1826  private:
1827  friend class bulk_write;
1828  friend class database;
1829 
1830  MONGOCXX_PRIVATE collection(const database& database,
1831  bsoncxx::string::view_or_value collection_name);
1832 
1833  MONGOCXX_PRIVATE collection(const database& database, void* collection);
1834 
1835  MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
1836  const pipeline& pipeline,
1837  const options::aggregate& options);
1838 
1839  MONGOCXX_PRIVATE std::int64_t _count(const client_session* session,
1841  const options::count& options);
1842 
1843  MONGOCXX_PRIVATE std::int64_t _count_documents(const client_session* session,
1845  const options::count& options);
1846 
1847  MONGOCXX_PRIVATE bsoncxx::document::value _create_index(
1848  const client_session* session,
1850  bsoncxx::document::view_or_value index_options,
1851  options::index_view operation_options);
1852 
1853  MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
1854  const client_session* session,
1856  const options::delete_options& options);
1857 
1858  MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
1859  const client_session* session,
1861  const options::delete_options& options);
1862 
1863  MONGOCXX_PRIVATE cursor _distinct(const client_session* session,
1866  const options::distinct& options);
1867 
1868  MONGOCXX_PRIVATE void _drop(
1869  const client_session* session,
1870  const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
1871 
1872  MONGOCXX_PRIVATE cursor _find(const client_session* session,
1874  const options::find& options);
1875 
1876  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one(
1877  const client_session* session,
1879  const options::find& options);
1880 
1881  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_delete(
1882  const client_session* session,
1884  const options::find_one_and_delete& options);
1885 
1886  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_replace(
1887  const client_session* session,
1890  const options::find_one_and_replace& options);
1891 
1892  MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_update(
1893  const client_session* session,
1896  const options::find_one_and_update& options);
1897 
1898  MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
1899  const client_session* session,
1901  const options::insert& options);
1902 
1903  MONGOCXX_PRIVATE void _rename(
1904  const client_session* session,
1906  bool drop_target_before_rename,
1907  const bsoncxx::stdx::optional<class write_concern>& write_concern);
1908 
1909  MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1910  const client_session* session,
1911  const options::bulk_write& bulk_opts,
1912  const model::replace_one& replace_op);
1913 
1914  MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1915  const client_session* session,
1918  const options::replace& options);
1919 
1920  MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
1921  const client_session* session,
1924  const options::update& options);
1925 
1926  MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
1927  const client_session* session,
1930  const options::update& options);
1931 
1932  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
1933  const pipeline& pipe,
1934  const options::change_stream& options);
1935 
1936  // Helpers for the insert_many method templates.
1937  class bulk_write _init_insert_many(const options::insert& options,
1938  const client_session* session);
1939 
1940  void _insert_many_doc_handler(class bulk_write& writes,
1941  bsoncxx::builder::basic::array& inserted_ids,
1942  bsoncxx::document::view doc) const;
1943 
1944  stdx::optional<result::insert_many> _exec_insert_many(
1945  class bulk_write& writes, bsoncxx::builder::basic::array& inserted_ids);
1946 
1947  template <typename document_view_iterator_type>
1948  MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
1949  const client_session* session,
1950  document_view_iterator_type begin,
1951  document_view_iterator_type end,
1952  const options::insert& options);
1953 
1954  class MONGOCXX_PRIVATE impl;
1955 
1956  MONGOCXX_PRIVATE impl& _get_impl();
1957  MONGOCXX_PRIVATE const impl& _get_impl() const;
1958 
1959  std::unique_ptr<impl> _impl;
1960 };
1961 
1962 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1963  const model::write& write, const options::bulk_write& options) {
1964  return create_bulk_write(options).append(write).execute();
1965 }
1966 
1967 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1968  const client_session& session, const model::write& write, const options::bulk_write& options) {
1969  return create_bulk_write(session, options).append(write).execute();
1970 }
1971 
1972 template <typename container_type>
1973 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1974  const container_type& requests, const options::bulk_write& options) {
1975  return bulk_write(requests.begin(), requests.end(), options);
1976 }
1977 
1978 template <typename container_type>
1979 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1980  const client_session& session,
1981  const container_type& requests,
1982  const options::bulk_write& options) {
1983  return bulk_write(session, requests.begin(), requests.end(), options);
1984 }
1985 
1986 template <typename write_model_iterator_type>
1987 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1988  write_model_iterator_type begin,
1989  write_model_iterator_type end,
1990  const options::bulk_write& options) {
1991  auto writes = create_bulk_write(options);
1992  std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
1993  return writes.execute();
1994 }
1995 
1996 template <typename write_model_iterator_type>
1997 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1998  const client_session& session,
1999  write_model_iterator_type begin,
2000  write_model_iterator_type end,
2001  const options::bulk_write& options) {
2002  auto writes = create_bulk_write(session, options);
2003  std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2004  return writes.execute();
2005 }
2006 
2007 template <typename container_type>
2008 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2009  const container_type& container, const options::insert& options) {
2010  return insert_many(container.begin(), container.end(), options);
2011 }
2012 
2013 template <typename container_type>
2014 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2015  const client_session& session,
2016  const container_type& container,
2017  const options::insert& options) {
2018  return insert_many(session, container.begin(), container.end(), options);
2019 }
2020 
2021 template <typename document_view_iterator_type>
2022 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
2023 
2024  const client_session* session,
2025  document_view_iterator_type begin,
2026  document_view_iterator_type end,
2027  const options::insert& options) {
2028  bsoncxx::builder::basic::array inserted_ids;
2029  auto writes = _init_insert_many(options, session);
2030  std::for_each(begin, end, [&inserted_ids, &writes, this](bsoncxx::document::view doc) {
2031  _insert_many_doc_handler(writes, inserted_ids, doc);
2032  });
2033  return _exec_insert_many(writes, inserted_ids);
2034 }
2035 
2036 template <typename document_view_iterator_type>
2037 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2038  document_view_iterator_type begin,
2039  document_view_iterator_type end,
2040  const options::insert& options) {
2041  return _insert_many(nullptr, begin, end, options);
2042 }
2043 
2044 template <typename document_view_iterator_type>
2045 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2046  const client_session& session,
2047  document_view_iterator_type begin,
2048  document_view_iterator_type end,
2049  const options::insert& options) {
2050  return _insert_many(&session, begin, end, options);
2051 }
2052 
2053 MONGOCXX_INLINE_NAMESPACE_END
2054 } // namespace mongocxx
2055 
2056 #include <mongocxx/config/postlude.hpp>
mongocxx::collection::watch
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
mongocxx::collection::update_many
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.
mongocxx::collection::write
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:1962
mongocxx::collection::delete_one
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.
mongocxx::collection::update_many
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.
mongocxx::collection::drop
void drop(const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops this collection and all its contained documents from the database.
mongocxx::change_stream
Definition: change_stream.hpp:31
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
mongocxx::collection::watch
change_stream watch(const options::change_stream &options={})
Gets a change stream on this collection with an empty pipeline.
mongocxx::collection::update_one
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.
bsoncxx::view_or_value< document::view, document::value >
mongocxx::collection::insert_one
stdx::optional< result::insert_one > insert_one(bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
mongocxx::options::aggregate
Class representing the optional arguments to a MongoDB aggregation operation.
Definition: aggregate.hpp:38
mongocxx::options::insert
Class representing the optional arguments to a MongoDB insert operation.
Definition: insert.hpp:31
mongocxx::options::estimated_document_count
Class representing the optional arguments to mongocxx::collection::estimated_document_count.
Definition: estimated_document_count.hpp:32
mongocxx::write_concern
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:56
mongocxx::collection::watch
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
mongocxx::collection::collection
collection() noexcept
Default constructs a collection object.
mongocxx::collection::distinct
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.
mongocxx::collection::replace_one
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.
mongocxx::options::find_one_and_delete
Class representing the optional arguments to a MongoDB find_and_modify delete operation.
Definition: find_one_and_delete.hpp:34
mongocxx::collection::watch
change_stream watch(const client_session &session, const options::change_stream &options={})
mongocxx::collection::name
stdx::string_view name() const
Returns the name of this collection.
mongocxx::collection::indexes
index_view indexes()
Gets an index_view to the collection.
mongocxx::collection::list_indexes
cursor list_indexes(const client_session &session) const
Returns a list of the indexes currently on this collection.
mongocxx::options::distinct
Class representing the optional arguments to a MongoDB distinct command.
Definition: distinct.hpp:34
mongocxx::collection::update_one
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.
mongocxx::collection::count_documents
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.
mongocxx::options::index_view
Class representing optional arguments to IndexView operations.
Definition: index_view.hpp:31
mongocxx::collection::write_concern
class write_concern write_concern() const
Gets the write_concern for the collection.
mongocxx::collection::find_one
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.
mongocxx::read_concern
A class to represent the read concern.
Definition: read_concern.hpp:54
mongocxx::collection::update_one
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.
mongocxx::collection::delete_many
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.
mongocxx::collection::insert_many
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:2008
bsoncxx::document::value
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:33
mongocxx::collection::find_one_and_update
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...
mongocxx::collection::read_concern
class read_concern read_concern() const
Gets the read_concern for the collection.
mongocxx::model::write
Models a single write operation within a mongocxx::bulk_write.
Definition: write.hpp:37
mongocxx::read_preference
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:62
mongocxx::collection::count_documents
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.
mongocxx::collection::find_one_and_update
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...
bsoncxx::string::view_or_value
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
mongocxx::options::find_one_and_update
Class representing the optional arguments to a MongoDB find_and_modify update operation.
Definition: find_one_and_update.hpp:37
mongocxx::collection::find_one
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.
mongocxx::collection::replace_one
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.
mongocxx::collection::delete_one
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.
mongocxx::collection::delete_many
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.
mongocxx::options::find
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:36
mongocxx::index_view
Definition: index_view.hpp:32
mongocxx::collection::update_many
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.
mongocxx::collection::find_one_and_replace
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...
mongocxx::collection::estimated_document_count
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.
mongocxx::collection::update_many
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.
mongocxx::collection::find_one_and_delete
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.
mongocxx::collection::update_one
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.
mongocxx::collection::insert_one
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.
mongocxx::options::update
Class representing the optional arguments to a MongoDB update operation.
Definition: update.hpp:33
mongocxx::collection::rename
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.
mongocxx::collection::find_one_and_update
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...
mongocxx::pipeline
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:38
bsoncxx::builder::basic::array
A traditional builder-style interface for constructing a BSON array.
Definition: array.hpp:35
mongocxx::options::change_stream
Definition: change_stream.hpp:35
mongocxx::client_session
Use a session for a sequence of operations, optionally with causal consistency.
Definition: client_session.hpp:39
mongocxx::bulk_write
Class representing a batch of write operations that can be sent to the server as a group.
Definition: bulk_write.hpp:43
mongocxx::collection::find
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.
mongocxx::database
Class representing a MongoDB database.
Definition: database.hpp:43
mongocxx::collection::find
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.
mongocxx::collection::update_many
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.
mongocxx::collection::update_one
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.
mongocxx::collection::find_one_and_update
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...
mongocxx::collection::find_one_and_update
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...
mongocxx::collection::find_one_and_delete
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.
mongocxx::options::delete_options
Class representing the optional arguments to a MongoDB delete operation.
Definition: delete.hpp:31
mongocxx::collection
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:83
mongocxx::model::replace_one
Class representing a MongoDB update operation that replaces a single document.
Definition: replace_one.hpp:31
mongocxx::collection::create_index
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.
mongocxx::collection::update_one
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.
mongocxx::options::replace
Class representing the optional arguments to a MongoDB replace operation.
Definition: replace.hpp:33
mongocxx::collection::find_one_and_update
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...
mongocxx::collection::drop
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.
mongocxx::options::bulk_write
Class representing the optional arguments to a MongoDB bulk write.
Definition: bulk_write.hpp:29
mongocxx::options::find_one_and_replace
Class representing the optional arguments to a MongoDB find_and_modify replace operation.
Definition: find_one_and_replace.hpp:36
mongocxx::collection::update_many
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.
mongocxx::options::count
Class representing the optional arguments to mongocxx::collection::count_documents.
Definition: count.hpp:36
mongocxx::cursor
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36
mongocxx::collection::read_preference
class read_preference read_preference() const
Gets the read_preference for the collection.
mongocxx::collection::list_indexes
cursor list_indexes() const
Returns a list of the indexes currently on this collection.
mongocxx::collection::create_index
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.
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
mongocxx::collection::distinct
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.
mongocxx::collection::rename
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.
mongocxx::collection::find_one_and_replace
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...