MongoDB C++ Driver  mongocxx-3.10.2
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 <mongocxx/bulk_write-fwd.hpp>
21 #include <mongocxx/client_encryption-fwd.hpp>
22 #include <mongocxx/collection-fwd.hpp>
23 #include <mongocxx/database-fwd.hpp>
24 
25 #include <bsoncxx/builder/basic/array.hpp>
26 #include <bsoncxx/builder/basic/document.hpp>
27 #include <bsoncxx/builder/basic/kvp.hpp>
28 #include <bsoncxx/builder/concatenate.hpp>
29 #include <bsoncxx/document/view_or_value.hpp>
30 #include <bsoncxx/oid.hpp>
31 #include <bsoncxx/stdx/optional.hpp>
32 #include <bsoncxx/string/view_or_value.hpp>
33 #include <mongocxx/bulk_write.hpp>
34 #include <mongocxx/change_stream.hpp>
35 #include <mongocxx/client_session.hpp>
36 #include <mongocxx/cursor.hpp>
37 #include <mongocxx/index_view.hpp>
38 #include <mongocxx/model/insert_one.hpp>
39 #include <mongocxx/options/aggregate.hpp>
40 #include <mongocxx/options/bulk_write.hpp>
41 #include <mongocxx/options/change_stream.hpp>
42 #include <mongocxx/options/count.hpp>
43 #include <mongocxx/options/delete.hpp>
44 #include <mongocxx/options/distinct.hpp>
45 #include <mongocxx/options/estimated_document_count.hpp>
46 #include <mongocxx/options/find.hpp>
47 #include <mongocxx/options/find_one_and_delete.hpp>
48 #include <mongocxx/options/find_one_and_replace.hpp>
49 #include <mongocxx/options/find_one_and_update.hpp>
50 #include <mongocxx/options/index.hpp>
51 #include <mongocxx/options/index_view.hpp>
52 #include <mongocxx/options/insert.hpp>
53 #include <mongocxx/options/replace.hpp>
54 #include <mongocxx/options/update.hpp>
55 #include <mongocxx/pipeline.hpp>
56 #include <mongocxx/read_concern.hpp>
57 #include <mongocxx/read_preference.hpp>
58 #include <mongocxx/result/bulk_write.hpp>
59 #include <mongocxx/result/delete.hpp>
60 #include <mongocxx/result/insert_many.hpp>
61 #include <mongocxx/result/insert_one.hpp>
62 #include <mongocxx/result/replace_one.hpp>
63 #include <mongocxx/result/update.hpp>
64 #include <mongocxx/search_index_view.hpp>
65 #include <mongocxx/write_concern.hpp>
66 
67 #include <mongocxx/config/prelude.hpp>
68 
69 namespace mongocxx {
70 namespace v_noabi {
71 
86 class collection {
87  //
88  // Utility class supporting the convenience of {} meaning an empty bsoncxx::v_noabi::document.
89  //
90  // Users may not use this class directly.
91  //
92  // In places where driver methods take this class as a parameter, passing {} will
93  // translate to a default-constructed bsoncxx::v_noabi::document::view_or_value,
94  // regardless of other overloads taking other default-constructible types
95  // for that parameter. This class avoids compiler ambiguity with such overloads.
96  //
97  // See collection::update_one for an example of such overloads.
98  //
99  class _empty_doc_tag {
100  _empty_doc_tag() = default;
101  };
102 
103  public:
110  collection() noexcept;
111 
115  collection(collection&&) noexcept;
116 
120  collection& operator=(collection&&) noexcept;
121 
126 
130  collection& operator=(const collection&);
131 
136 
141  explicit operator bool() const noexcept;
142 
165  const options::aggregate& options = options::aggregate());
166 
189  const pipeline& pipeline,
190  const options::aggregate& options = options::aggregate());
194 
207  mongocxx::v_noabi::bulk_write create_bulk_write(const options::bulk_write& options = {});
208 
222  const options::bulk_write& options = {});
226 
249  MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
250  const model::write& write, const options::bulk_write& options = options::bulk_write());
251 
274  MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
275  const client_session& session,
276  const model::write& write,
277  const options::bulk_write& options = options::bulk_write());
281 
305  template <typename container_type>
306  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
307  const container_type& writes, const options::bulk_write& options = options::bulk_write());
308 
332  template <typename container_type>
333  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
334  const client_session& session,
335  const container_type& writes,
336  const options::bulk_write& options = options::bulk_write());
340 
365  template <typename write_model_iterator_type>
366  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
367  write_model_iterator_type begin,
368  write_model_iterator_type end,
369  const options::bulk_write& options = options::bulk_write());
370 
395  template <typename write_model_iterator_type>
396  MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
397  const client_session& session,
398  write_model_iterator_type begin,
399  write_model_iterator_type end,
400  const options::bulk_write& options = options::bulk_write());
404 
430  const options::count& options = options::count());
431 
453  std::int64_t count_documents(const client_session& session,
455  const options::count& options = options::count());
459 
482 
507  options::index_view operation_options = options::index_view{});
508 
531  const client_session& session,
534  options::index_view operation_options = options::index_view{});
535 
539 
558  stdx::optional<result::delete_result> delete_many(
561 
580  stdx::optional<result::delete_result> delete_many(
581  const client_session& session,
584 
588 
607  stdx::optional<result::delete_result> delete_one(
610 
629  stdx::optional<result::delete_result> delete_one(
630  const client_session& session,
633 
637 
649 
653 
658  const options::distinct& options = options::distinct());
659 
671 
675 
681  const options::distinct& options = options::distinct());
682 
686 
708  void drop(const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>&
709  write_concern = {},
710  bsoncxx::v_noabi::document::view_or_value collection_options = {});
711 
732  void drop(const client_session& session,
733  const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>&
734  write_concern = {},
735  bsoncxx::v_noabi::document::view_or_value collection_options = {});
736 
740 
761  const options::find& options = options::find());
762 
782  cursor find(const client_session& session,
784  const options::find& options = options::find());
785 
802  stdx::optional<bsoncxx::v_noabi::document::value> find_one(
804  const options::find& options = options::find());
805 
822  stdx::optional<bsoncxx::v_noabi::document::value> find_one(
823  const client_session& session,
825  const options::find& options = options::find());
826 
830 
850  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_delete(
853 
873  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_delete(
874  const client_session& session,
877 
881 
904  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_replace(
908 
931  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_replace(
932  const client_session& session,
936 
940 
963  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_update(
967 
988  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_update(
990  const pipeline& update,
992 
1013  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_update(
1015  std::initializer_list<_empty_doc_tag> update,
1017 
1040  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_update(
1041  const client_session& session,
1045 
1068  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_update(
1069  const client_session& session,
1071  const pipeline& update,
1073 
1096  stdx::optional<bsoncxx::v_noabi::document::value> find_one_and_update(
1097  const client_session& session,
1099  std::initializer_list<_empty_doc_tag> update,
1101 
1105 
1122  stdx::optional<result::insert_one> insert_one(
1123  bsoncxx::v_noabi::document::view_or_value document, const options::insert& options = {});
1140  stdx::optional<result::insert_one> insert_one(
1141  const client_session& session,
1143  const options::insert& options = {});
1147 
1173  template <typename container_type>
1174  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1175  const container_type& container, const options::insert& options = options::insert());
1176 
1198  template <typename container_type>
1199  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1200  const client_session& session,
1201  const container_type& container,
1202  const options::insert& options = options::insert());
1203 
1229  template <typename document_view_iterator_type>
1230  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1231  document_view_iterator_type begin,
1232  document_view_iterator_type end,
1233  const options::insert& options = options::insert());
1234 
1256  template <typename document_view_iterator_type>
1257  MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1258  const client_session& session,
1259  document_view_iterator_type begin,
1260  document_view_iterator_type end,
1261  const options::insert& options = options::insert());
1265 
1278 
1291  cursor list_indexes(const client_session& session) const;
1292 
1296 
1303  stdx::string_view name() const;
1304 
1325  bool drop_target_before_rename = false,
1326  const bsoncxx::v_noabi::stdx::optional<write_concern>& write_concern = {});
1327 
1349  void rename(const client_session& session,
1351  bool drop_target_before_rename = false,
1352  const bsoncxx::v_noabi::stdx::optional<write_concern>& write_concern = {});
1353 
1357 
1368 
1378 
1389 
1398 
1421  stdx::optional<result::replace_one> replace_one(
1424  const options::replace& options = options::replace{});
1425 
1448  stdx::optional<result::replace_one> replace_one(
1449  const client_session& session,
1452  const options::replace& options = options::replace{});
1453 
1476  stdx::optional<result::update> update_many(bsoncxx::v_noabi::document::view_or_value filter,
1478  const options::update& options = options::update());
1479 
1500  stdx::optional<result::update> update_many(bsoncxx::v_noabi::document::view_or_value filter,
1501  const pipeline& update,
1502  const options::update& options = options::update());
1503 
1524  stdx::optional<result::update> update_many(bsoncxx::v_noabi::document::view_or_value filter,
1525  std::initializer_list<_empty_doc_tag> update,
1526  const options::update& options = options::update());
1527 
1550  stdx::optional<result::update> update_many(const client_session& session,
1553  const options::update& options = options::update());
1554 
1577  stdx::optional<result::update> update_many(const client_session& session,
1579  const pipeline& update,
1580  const options::update& options = options::update());
1581 
1604  stdx::optional<result::update> update_many(const client_session& session,
1606  std::initializer_list<_empty_doc_tag> update,
1607  const options::update& options = options::update());
1608 
1612 
1635  stdx::optional<result::update> update_one(bsoncxx::v_noabi::document::view_or_value filter,
1637  const options::update& options = options::update());
1638 
1659  stdx::optional<result::update> update_one(bsoncxx::v_noabi::document::view_or_value filter,
1660  const pipeline& update,
1661  const options::update& options = options::update());
1662 
1683  stdx::optional<result::update> update_one(bsoncxx::v_noabi::document::view_or_value filter,
1684  std::initializer_list<_empty_doc_tag> update,
1685  const options::update& options = options::update());
1686 
1709  stdx::optional<result::update> update_one(const client_session& session,
1712  const options::update& options = options::update());
1713 
1736  stdx::optional<result::update> update_one(const client_session& session,
1738  const pipeline& update,
1739  const options::update& options = options::update());
1740 
1763  stdx::optional<result::update> update_one(const client_session& session,
1765  std::initializer_list<_empty_doc_tag> update,
1766  const options::update& options = options::update());
1767 
1771 
1780 
1787 
1791 
1807 
1819  change_stream watch(const client_session& session, const options::change_stream& options = {});
1820 
1837  change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
1838 
1855  const pipeline& pipe,
1856  const options::change_stream& options = {});
1857 
1861 
1865 
1866  private:
1867  friend ::mongocxx::v_noabi::bulk_write;
1868  friend ::mongocxx::v_noabi::client_encryption;
1869  friend ::mongocxx::v_noabi::database;
1870 
1871  MONGOCXX_PRIVATE collection(const database& database,
1872  bsoncxx::v_noabi::string::view_or_value collection_name);
1873 
1874  MONGOCXX_PRIVATE collection(const database& database, void* collection);
1875 
1876  MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
1877  const pipeline& pipeline,
1878  const options::aggregate& options);
1879 
1880  MONGOCXX_PRIVATE std::int64_t _count(const client_session* session,
1882  const options::count& options);
1883 
1884  MONGOCXX_PRIVATE std::int64_t _count_documents(const client_session* session,
1886  const options::count& options);
1887 
1888  MONGOCXX_PRIVATE bsoncxx::v_noabi::document::value _create_index(
1889  const client_session* session,
1892  options::index_view operation_options);
1893 
1894  MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
1895  const client_session* session,
1897  const options::delete_options& options);
1898 
1899  MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
1900  const client_session* session,
1902  const options::delete_options& options);
1903 
1904  MONGOCXX_PRIVATE cursor _distinct(const client_session* session,
1907  const options::distinct& options);
1908 
1909  MONGOCXX_PRIVATE void _drop(
1910  const client_session* session,
1911  const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>& write_concern,
1912  bsoncxx::v_noabi::document::view_or_value collection_options);
1913 
1914  MONGOCXX_PRIVATE cursor _find(const client_session* session,
1916  const options::find& options);
1917 
1918  MONGOCXX_PRIVATE stdx::optional<bsoncxx::v_noabi::document::value> _find_one(
1919  const client_session* session,
1921  const options::find& options);
1922 
1923  MONGOCXX_PRIVATE stdx::optional<bsoncxx::v_noabi::document::value> _find_one_and_delete(
1924  const client_session* session,
1926  const options::find_one_and_delete& options);
1927 
1928  MONGOCXX_PRIVATE stdx::optional<bsoncxx::v_noabi::document::value> _find_one_and_replace(
1929  const client_session* session,
1932  const options::find_one_and_replace& options);
1933 
1934  MONGOCXX_PRIVATE stdx::optional<bsoncxx::v_noabi::document::value> _find_one_and_update(
1935  const client_session* session,
1938  const options::find_one_and_update& options);
1939 
1940  MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
1941  const client_session* session,
1943  const options::insert& options);
1944 
1945  MONGOCXX_PRIVATE void _rename(
1946  const client_session* session,
1948  bool drop_target_before_rename,
1949  const bsoncxx::v_noabi::stdx::optional<mongocxx::v_noabi::write_concern>& write_concern);
1950 
1951  MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1952  const client_session* session,
1953  const options::bulk_write& bulk_opts,
1954  const model::replace_one& replace_op);
1955 
1956  MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1957  const client_session* session,
1960  const options::replace& options);
1961 
1962  MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
1963  const client_session* session,
1966  const options::update& options);
1967 
1968  MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
1969  const client_session* session,
1972  const options::update& options);
1973 
1974  MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
1975  const pipeline& pipe,
1976  const options::change_stream& options);
1977 
1978  // Helpers for the insert_many method templates.
1979  mongocxx::v_noabi::bulk_write _init_insert_many(const options::insert& options,
1980  const client_session* session);
1981 
1982  void _insert_many_doc_handler(mongocxx::v_noabi::bulk_write& writes,
1985 
1986  stdx::optional<result::insert_many> _exec_insert_many(
1989 
1990  template <typename document_view_iterator_type>
1991  MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
1992  const client_session* session,
1993  document_view_iterator_type begin,
1994  document_view_iterator_type end,
1995  const options::insert& options);
1996 
1997  class MONGOCXX_PRIVATE impl;
1998 
1999  MONGOCXX_PRIVATE impl& _get_impl();
2000  MONGOCXX_PRIVATE const impl& _get_impl() const;
2001 
2002  std::unique_ptr<impl> _impl;
2003 };
2004 
2005 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
2006  const model::write& write, const options::bulk_write& options) {
2007  return create_bulk_write(options).append(write).execute();
2008 }
2009 
2010 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
2011  const client_session& session, const model::write& write, const options::bulk_write& options) {
2012  return create_bulk_write(session, options).append(write).execute();
2013 }
2014 
2015 template <typename container_type>
2016 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2017  const container_type& requests, const options::bulk_write& options) {
2018  return bulk_write(requests.begin(), requests.end(), options);
2019 }
2020 
2021 template <typename container_type>
2022 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2023  const client_session& session,
2024  const container_type& requests,
2025  const options::bulk_write& options) {
2026  return bulk_write(session, requests.begin(), requests.end(), options);
2027 }
2028 
2029 template <typename write_model_iterator_type>
2030 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2031  write_model_iterator_type begin,
2032  write_model_iterator_type end,
2033  const options::bulk_write& options) {
2034  auto writes = create_bulk_write(options);
2035  std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2036  return writes.execute();
2037 }
2038 
2039 template <typename write_model_iterator_type>
2040 MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
2041  const client_session& session,
2042  write_model_iterator_type begin,
2043  write_model_iterator_type end,
2044  const options::bulk_write& options) {
2045  auto writes = create_bulk_write(session, options);
2046  std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
2047  return writes.execute();
2048 }
2049 
2050 template <typename container_type>
2051 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2052  const container_type& container, const options::insert& options) {
2053  return insert_many(container.begin(), container.end(), options);
2054 }
2055 
2056 template <typename container_type>
2057 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2058  const client_session& session,
2059  const container_type& container,
2060  const options::insert& options) {
2061  return insert_many(session, container.begin(), container.end(), options);
2062 }
2063 
2064 template <typename document_view_iterator_type>
2065 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
2066 
2067  const client_session* session,
2068  document_view_iterator_type begin,
2069  document_view_iterator_type end,
2070  const options::insert& options) {
2072  auto writes = _init_insert_many(options, session);
2073  std::for_each(begin, end, [&inserted_ids, &writes, this](bsoncxx::v_noabi::document::view doc) {
2074  _insert_many_doc_handler(writes, inserted_ids, doc);
2075  });
2076  return _exec_insert_many(writes, inserted_ids);
2077 }
2078 
2079 template <typename document_view_iterator_type>
2080 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2081  document_view_iterator_type begin,
2082  document_view_iterator_type end,
2083  const options::insert& options) {
2084  return _insert_many(nullptr, begin, end, options);
2085 }
2086 
2087 template <typename document_view_iterator_type>
2088 MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
2089  const client_session& session,
2090  document_view_iterator_type begin,
2091  document_view_iterator_type end,
2092  const options::insert& options) {
2093  return _insert_many(&session, begin, end, options);
2094 }
2095 
2096 } // namespace v_noabi
2097 } // namespace mongocxx
2098 
2099 #include <mongocxx/config/postlude.hpp>
A traditional builder-style interface for constructing a BSON array.
Definition: array.hpp:37
A read-only BSON document that owns its underlying buffer.
Definition: value.hpp:38
A read-only, non-owning view of a BSON document.
Definition: view.hpp:35
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:38
Class representing a batch of write operations that can be sent to the server as a group.
Definition: bulk_write.hpp:44
stdx::optional< result::bulk_write > execute() const
Executes a bulk write.
bulk_write & append(const model::write &operation)
Appends a single write to the bulk write operation.
Class representing a MongoDB change stream.
Definition: change_stream.hpp:35
Use a session for a sequence of operations, optionally with either causal consistency or snapshots.
Definition: client_session.hpp:47
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:86
stdx::optional< result::update > update_one(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
mongocxx::v_noabi::read_preference read_preference() const
Gets the read_preference for the collection.
std::int64_t count_documents(bsoncxx::v_noabi::document::view_or_value filter, const options::count &options=options::count())
Counts the number of documents matching the provided filter.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_update(bsoncxx::v_noabi::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...
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_update(const client_session &session, bsoncxx::v_noabi::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...
search_index_view search_indexes()
Gets a search_index_view to the collection.
stdx::optional< result::update > update_many(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, const pipeline &update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
void read_concern(mongocxx::v_noabi::read_concern rc)
Sets the read_concern for this collection.
void rename(const client_session &session, bsoncxx::v_noabi::string::view_or_value new_name, bool drop_target_before_rename=false, const bsoncxx::v_noabi::stdx::optional< write_concern > &write_concern={})
Rename this collection.
bsoncxx::v_noabi::document::value create_index(bsoncxx::v_noabi::document::view_or_value keys, bsoncxx::v_noabi::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.
void drop(const client_session &session, const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > &write_concern={}, bsoncxx::v_noabi::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::v_noabi::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::string_view name() const
Returns the name of this collection.
cursor aggregate(const pipeline &pipeline, const options::aggregate &options=options::aggregate())
Runs an aggregation framework pipeline against this collection.
stdx::optional< result::delete_result > delete_many(bsoncxx::v_noabi::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes all matching documents from the collection.
bsoncxx::v_noabi::document::value create_index(const client_session &session, bsoncxx::v_noabi::document::view_or_value keys, bsoncxx::v_noabi::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.
void write_concern(mongocxx::v_noabi::write_concern wc)
Sets the write_concern for this collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one(const client_session &session, bsoncxx::v_noabi::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 options::change_stream &options={})
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_delete(const client_session &session, bsoncxx::v_noabi::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::insert_many > insert_many(const container_type &container, const options::insert &options=options::insert())
Inserts multiple documents into the collection.
Definition: collection.hpp:2051
change_stream watch(const options::change_stream &options={})
Gets a change stream on this collection with an empty pipeline.
stdx::optional< result::update > update_one(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
void drop(const bsoncxx::v_noabi::stdx::optional< mongocxx::v_noabi::write_concern > &write_concern={}, bsoncxx::v_noabi::document::view_or_value collection_options={})
Drops this collection and all its contained documents from the database.
stdx::optional< bsoncxx::v_noabi::document::value > find_one(bsoncxx::v_noabi::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 count_documents(const client_session &session, bsoncxx::v_noabi::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(bsoncxx::v_noabi::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
stdx::optional< result::update > update_many(bsoncxx::v_noabi::document::view_or_value filter, const pipeline &update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
cursor list_indexes() const
Returns a list of the indexes currently on this collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_replace(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::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...
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
cursor distinct(bsoncxx::v_noabi::string::view_or_value name, bsoncxx::v_noabi::document::view_or_value filter, const options::distinct &options=options::distinct())
Finds the distinct values for a specified field across the collection.
stdx::optional< result::update > update_many(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
mongocxx::v_noabi::read_concern read_concern() const
Gets the read_concern for the collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_update(const client_session &session, bsoncxx::v_noabi::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...
void read_preference(mongocxx::v_noabi::read_preference rp)
Sets the read_preference for this collection.
stdx::optional< result::delete_result > delete_many(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes all matching documents from the collection.
stdx::optional< result::update > update_many(bsoncxx::v_noabi::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::update &options=options::update())
Updates multiple documents matching the provided filter in this collection.
stdx::optional< result::update > update_one(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
stdx::optional< result::update > update_one(bsoncxx::v_noabi::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 rename(bsoncxx::v_noabi::string::view_or_value new_name, bool drop_target_before_rename=false, const bsoncxx::v_noabi::stdx::optional< write_concern > &write_concern={})
Rename this collection.
index_view indexes()
Gets an index_view to the collection.
stdx::optional< result::insert_one > insert_one(const client_session &session, bsoncxx::v_noabi::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_replace(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::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< bsoncxx::v_noabi::document::value > find_one_and_update(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::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::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:2016
mongocxx::v_noabi::write_concern write_concern() const
Gets the write_concern for the collection.
stdx::optional< result::update > update_one(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, const pipeline &update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_delete(bsoncxx::v_noabi::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::v_noabi::bulk_write create_bulk_write(const options::bulk_write &options={})
Creates a new bulk operation to be executed against 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:2005
stdx::optional< result::replace_one > replace_one(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value replacement, const options::replace &options=options::replace{})
Replaces a single document matching the provided filter in this collection.
collection() noexcept
Default constructs a collection object.
stdx::optional< result::replace_one > replace_one(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value replacement, const options::replace &options=options::replace{})
Replaces a single document matching the provided filter in this collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_update(bsoncxx::v_noabi::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...
cursor find(bsoncxx::v_noabi::document::view_or_value filter, const options::find &options=options::find())
Finds the documents in this collection which match the provided filter.
cursor distinct(const client_session &session, bsoncxx::v_noabi::string::view_or_value name, bsoncxx::v_noabi::document::view_or_value filter, const options::distinct &options=options::distinct())
Finds the distinct values for a specified field across the collection.
cursor find(const client_session &session, bsoncxx::v_noabi::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::delete_result > delete_one(const client_session &session, bsoncxx::v_noabi::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes a single matching document from the collection.
cursor list_indexes(const client_session &session) const
Returns a list of the indexes currently on this collection.
stdx::optional< result::delete_result > delete_one(bsoncxx::v_noabi::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes a single matching document from the collection.
stdx::optional< bsoncxx::v_noabi::document::value > find_one_and_update(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::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::insert_one > insert_one(bsoncxx::v_noabi::document::view_or_value document, const options::insert &options={})
Inserts a single document into the 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.
mongocxx::v_noabi::bulk_write create_bulk_write(const client_session &session, const options::bulk_write &options={})
Creates a new bulk operation to be executed against this collection.
stdx::optional< result::update > update_many(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value update, const options::update &options=options::update())
Updates multiple documents 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:42
Class representing a MongoDB database.
Definition: database.hpp:46
Class representing a MongoDB index view.
Definition: index_view.hpp:38
Class representing a MongoDB update operation that replaces a single document.
Definition: replace_one.hpp:33
Models a single write operation within a mongocxx::v_noabi::bulk_write.
Definition: write.hpp:39
Class representing the optional arguments to a MongoDB aggregation operation.
Definition: aggregate.hpp:43
Class representing the optional arguments to a MongoDB bulk write.
Definition: bulk_write.hpp:33
Class representing MongoDB change stream options.
Definition: change_stream.hpp:39
Class representing the optional arguments to mongocxx::v_noabi::collection::count_documents.
Definition: count.hpp:38
Class representing the optional arguments to a MongoDB delete operation.
Definition: delete.hpp:34
Class representing the optional arguments to a MongoDB distinct command.
Definition: distinct.hpp:37
Class representing the optional arguments to mongocxx::v_noabi::collection::estimated_document_count.
Definition: estimated_document_count.hpp:35
Class representing the optional arguments to a MongoDB find_and_modify delete operation.
Definition: find_one_and_delete.hpp:37
Class representing the optional arguments to a MongoDB find_and_modify replace operation.
Definition: find_one_and_replace.hpp:39
Class representing the optional arguments to a MongoDB find_and_modify update operation.
Definition: find_one_and_update.hpp:40
Class representing the optional arguments to a MongoDB query.
Definition: find.hpp:39
Class representing optional arguments to IndexView operations.
Definition: index_view.hpp:33
Class representing the optional arguments to a MongoDB insert operation.
Definition: insert.hpp:34
Class representing the optional arguments to a MongoDB replace operation.
Definition: replace.hpp:36
Class representing the optional arguments to a MongoDB update operation.
Definition: update.hpp:36
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:39
A class to represent the read concern.
Definition: read_concern.hpp:56
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition: read_preference.hpp:63
Class representing a MongoDB search index view.
Definition: search_index_view.hpp:23
Class representing the server-side requirement for reporting the success of a write operation.
Definition: write_concern.hpp:58
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19