MongoDB C++ Driver mongocxx-3.4.0
Loading...
Searching...
No Matches
collection.hpp
1// Copyright 2014-present MongoDB Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <algorithm>
18#include <cstdint>
19#include <memory>
20#include <string>
21
22#include <bsoncxx/builder/basic/array.hpp>
23#include <bsoncxx/builder/basic/document.hpp>
24#include <bsoncxx/builder/basic/kvp.hpp>
25#include <bsoncxx/builder/concatenate.hpp>
26#include <bsoncxx/document/view_or_value.hpp>
27#include <bsoncxx/oid.hpp>
28#include <bsoncxx/stdx/optional.hpp>
29#include <bsoncxx/string/view_or_value.hpp>
30#include <mongocxx/bulk_write.hpp>
31#include <mongocxx/change_stream.hpp>
32#include <mongocxx/client_session.hpp>
33#include <mongocxx/cursor.hpp>
34#include <mongocxx/index_view.hpp>
35#include <mongocxx/model/insert_one.hpp>
36#include <mongocxx/options/aggregate.hpp>
37#include <mongocxx/options/bulk_write.hpp>
38#include <mongocxx/options/change_stream.hpp>
39#include <mongocxx/options/count.hpp>
40#include <mongocxx/options/delete.hpp>
41#include <mongocxx/options/distinct.hpp>
42#include <mongocxx/options/estimated_document_count.hpp>
43#include <mongocxx/options/find.hpp>
44#include <mongocxx/options/find_one_and_delete.hpp>
45#include <mongocxx/options/find_one_and_replace.hpp>
46#include <mongocxx/options/find_one_and_update.hpp>
47#include <mongocxx/options/index.hpp>
48#include <mongocxx/options/index_view.hpp>
49#include <mongocxx/options/insert.hpp>
50#include <mongocxx/options/replace.hpp>
51#include <mongocxx/options/update.hpp>
52#include <mongocxx/pipeline.hpp>
53#include <mongocxx/read_concern.hpp>
54#include <mongocxx/read_preference.hpp>
55#include <mongocxx/result/bulk_write.hpp>
56#include <mongocxx/result/delete.hpp>
57#include <mongocxx/result/insert_many.hpp>
58#include <mongocxx/result/insert_one.hpp>
59#include <mongocxx/result/replace_one.hpp>
60#include <mongocxx/result/update.hpp>
61#include <mongocxx/write_concern.hpp>
62
63#include <mongocxx/config/prelude.hpp>
64
65namespace mongocxx {
66MONGOCXX_INLINE_NAMESPACE_BEGIN
67
68class client;
69class database;
70
85class MONGOCXX_API collection {
86 public:
93 collection() noexcept;
94
99
103 collection& operator=(collection&&) noexcept;
104
109
113 collection& operator=(const collection&);
114
119
124 explicit operator bool() const noexcept;
125
147 cursor aggregate(const pipeline& pipeline,
148 const options::aggregate& options = options::aggregate());
149
171 cursor aggregate(const client_session& session,
172 const pipeline& pipeline,
173 const options::aggregate& options = options::aggregate());
177
190 class bulk_write create_bulk_write(const options::bulk_write& options = {});
191
204 class bulk_write create_bulk_write(const client_session& session,
205 const options::bulk_write& options = {});
209
232 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
233 const model::write& write, const options::bulk_write& options = options::bulk_write());
234
257 MONGOCXX_INLINE stdx::optional<result::bulk_write> write(
258 const client_session& session,
259 const model::write& write,
260 const options::bulk_write& options = options::bulk_write());
264
288 template <typename container_type>
289 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
290 const container_type& writes, const options::bulk_write& options = options::bulk_write());
291
315 template <typename container_type>
316 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
317 const client_session& session,
318 const container_type& writes,
319 const options::bulk_write& options = options::bulk_write());
323
348 template <typename write_model_iterator_type>
349 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
350 write_model_iterator_type begin,
351 write_model_iterator_type end,
352 const options::bulk_write& options = options::bulk_write());
353
378 template <typename write_model_iterator_type>
379 MONGOCXX_INLINE stdx::optional<result::bulk_write> bulk_write(
380 const client_session& session,
381 write_model_iterator_type begin,
382 write_model_iterator_type end,
383 const options::bulk_write& options = options::bulk_write());
387
388 // clang-format off
428 // clang-format on
429 MONGOCXX_DEPRECATED std::int64_t count(bsoncxx::document::view_or_value filter,
430 const options::count& options = options::count());
431
433 const options::count& options = options::count());
434
435 // clang-format off
475 // clang-format on
476 MONGOCXX_DEPRECATED std::int64_t count(const client_session& session,
478 const options::count& options = options::count());
479
480 std::int64_t count_deprecated(const client_session& session,
482 const options::count& options = options::count());
486
502 const options::count& options = options::count());
503
518 std::int64_t count_documents(const client_session& session,
520 const options::count& options = options::count());
524
542
566 bsoncxx::document::view_or_value index_options = {},
567 options::index_view operation_options = options::index_view{});
568
591 const client_session& session,
593 bsoncxx::document::view_or_value index_options = {},
594 options::index_view operation_options = options::index_view{});
595
599
618 stdx::optional<result::delete_result> delete_many(
621
640 stdx::optional<result::delete_result> delete_many(
641 const client_session& session,
644
648
667 stdx::optional<result::delete_result> delete_one(
670
689 stdx::optional<result::delete_result> delete_one(
690 const client_session& session,
693
697
709
713
718 const options::distinct& options = options::distinct());
719
731
735
741 const options::distinct& options = options::distinct());
742
746
765 void drop(const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
766
785 void drop(const client_session& session,
786 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern = {});
787
791
812 const options::find& options = options::find());
813
833 cursor find(const client_session& session,
835 const options::find& options = options::find());
836
853 stdx::optional<bsoncxx::document::value> find_one(
855
872 stdx::optional<bsoncxx::document::value> find_one(
873 const client_session& session,
875 const options::find& options = options::find());
876
880
900 stdx::optional<bsoncxx::document::value> find_one_and_delete(
903
923 stdx::optional<bsoncxx::document::value> find_one_and_delete(
924 const client_session& session,
927
931
954 stdx::optional<bsoncxx::document::value> find_one_and_replace(
958
981 stdx::optional<bsoncxx::document::value> find_one_and_replace(
982 const client_session& session,
986
990
1013 stdx::optional<bsoncxx::document::value> find_one_and_update(
1017
1040 stdx::optional<bsoncxx::document::value> find_one_and_update(
1041 const client_session& session,
1045
1049
1066 stdx::optional<result::insert_one> insert_one(bsoncxx::document::view_or_value document,
1067 const options::insert& options = {});
1084 stdx::optional<result::insert_one> insert_one(const client_session& session,
1086 const options::insert& options = {});
1090
1116 template <typename container_type>
1117 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1118 const container_type& container, const options::insert& options = options::insert());
1119
1141 template <typename container_type>
1142 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1143 const client_session& session,
1144 const container_type& container,
1145 const options::insert& options = options::insert());
1146
1172 template <typename document_view_iterator_type>
1173 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1174 document_view_iterator_type begin,
1175 document_view_iterator_type end,
1176 const options::insert& options = options::insert());
1177
1199 template <typename document_view_iterator_type>
1200 MONGOCXX_INLINE stdx::optional<result::insert_many> insert_many(
1201 const client_session& session,
1202 document_view_iterator_type begin,
1203 document_view_iterator_type end,
1204 const options::insert& options = options::insert());
1208
1221
1234 cursor list_indexes(const client_session& session) const;
1235
1239
1246 stdx::string_view name() const;
1247
1268 bool drop_target_before_rename = false,
1269 const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1270
1292 void rename(const client_session& session,
1294 bool drop_target_before_rename = false,
1295 const bsoncxx::stdx::optional<write_concern>& write_concern = {});
1296
1300
1311
1321
1332
1341
1364 stdx::optional<result::replace_one> replace_one(
1367 const options::replace& options = options::replace{});
1368
1391 stdx::optional<result::replace_one> replace_one(
1392 const client_session& session,
1395 const options::replace& options = options::replace{});
1396
1421 template <typename T,
1422 typename std::enable_if<std::is_same<T, options::update>::value, int>::type = 0>
1423 MONGOCXX_DEPRECATED stdx::optional<result::replace_one> replace_one(
1426 const T& options) {
1427 return replace_one_deprecated(filter, replacement, options);
1428 }
1429
1430 stdx::optional<result::replace_one> replace_one_deprecated(
1433 const options::update& options);
1434
1461 template <typename T,
1462 typename std::enable_if<std::is_same<T, options::update>::value, int>::type = 0>
1463 MONGOCXX_DEPRECATED stdx::optional<result::replace_one> replace_one(
1464 const client_session& session,
1467 const T& options) {
1468 return replace_one_deprecated(session, filter, replacement, options);
1469 }
1470
1471 stdx::optional<result::replace_one> replace_one_deprecated(
1472 const client_session& session,
1475 const options::update& options);
1476
1480
1503 stdx::optional<result::update> update_many(bsoncxx::document::view_or_value filter,
1505 const options::update& options = options::update());
1506
1529 stdx::optional<result::update> update_many(const client_session& session,
1532 const options::update& options = options::update());
1533
1537
1560 stdx::optional<result::update> update_one(bsoncxx::document::view_or_value filter,
1562 const options::update& options = options::update());
1563
1586 stdx::optional<result::update> update_one(const client_session& session,
1589 const options::update& options = options::update());
1590
1594
1603
1610
1614
1630
1642 change_stream watch(const client_session& session, const options::change_stream& options = {});
1643
1660 change_stream watch(const pipeline& pipe, const options::change_stream& options = {});
1661
1678 const pipeline& pipe,
1679 const options::change_stream& options = {});
1680
1684
1685 private:
1686 friend class bulk_write;
1687 friend class database;
1688
1689 MONGOCXX_PRIVATE collection(const database& database,
1690 bsoncxx::string::view_or_value collection_name);
1691
1692 MONGOCXX_PRIVATE collection(const database& database, void* collection);
1693
1694 MONGOCXX_PRIVATE cursor _aggregate(const client_session* session,
1695 const pipeline& pipeline,
1696 const options::aggregate& options);
1697
1698 MONGOCXX_PRIVATE std::int64_t _count(const client_session* session,
1700 const options::count& options);
1701
1702 MONGOCXX_PRIVATE std::int64_t _count_documents(const client_session* session,
1704 const options::count& options);
1705
1706 MONGOCXX_PRIVATE bsoncxx::document::value _create_index(
1707 const client_session* session,
1710 options::index_view operation_options);
1711
1712 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_many(
1713 const client_session* session,
1715 const options::delete_options& options);
1716
1717 MONGOCXX_PRIVATE stdx::optional<result::delete_result> _delete_one(
1718 const client_session* session,
1720 const options::delete_options& options);
1721
1722 MONGOCXX_PRIVATE cursor _distinct(const client_session* session,
1725 const options::distinct& options);
1726
1727 MONGOCXX_PRIVATE void _drop(
1728 const client_session* session,
1729 const bsoncxx::stdx::optional<mongocxx::write_concern>& write_concern);
1730
1731 MONGOCXX_PRIVATE cursor _find(const client_session* session,
1733 const options::find& options);
1734
1735 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one(
1736 const client_session* session,
1738 const options::find& options);
1739
1740 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_delete(
1741 const client_session* session,
1743 const options::find_one_and_delete& options);
1744
1745 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_replace(
1746 const client_session* session,
1749 const options::find_one_and_replace& options);
1750
1751 MONGOCXX_PRIVATE stdx::optional<bsoncxx::document::value> _find_one_and_update(
1752 const client_session* session,
1755 const options::find_one_and_update& options);
1756
1757 MONGOCXX_PRIVATE stdx::optional<result::insert_one> _insert_one(
1758 const client_session* session,
1760 const options::insert& options);
1761
1762 MONGOCXX_PRIVATE void _rename(
1763 const client_session* session,
1765 bool drop_target_before_rename,
1766 const bsoncxx::stdx::optional<class write_concern>& write_concern);
1767
1768 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1769 const client_session* session,
1770 const options::bulk_write& bulk_opts,
1771 const model::replace_one& replace_op);
1772
1773 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1774 const client_session* session,
1777 const options::replace& options);
1778
1779 MONGOCXX_PRIVATE stdx::optional<result::replace_one> _replace_one(
1780 const client_session* session,
1783 const options::update& options);
1784
1785 MONGOCXX_PRIVATE stdx::optional<result::update> _update_one(
1786 const client_session* session,
1789 const options::update& options);
1790
1791 MONGOCXX_PRIVATE stdx::optional<result::update> _update_many(
1792 const client_session* session,
1795 const options::update& options);
1796
1797 MONGOCXX_PRIVATE change_stream _watch(const client_session* session,
1798 const pipeline& pipe,
1799 const options::change_stream& options);
1800
1801 // Helpers for the insert_many method templates.
1802 class bulk_write _init_insert_many(const options::insert& options,
1803 const client_session* session);
1804
1805 void _insert_many_doc_handler(class bulk_write& writes,
1806 bsoncxx::builder::basic::array& inserted_ids,
1807 bsoncxx::document::view doc) const;
1808
1809 stdx::optional<result::insert_many> _exec_insert_many(
1810 class bulk_write& writes, bsoncxx::builder::basic::array& inserted_ids);
1811
1812 template <typename document_view_iterator_type>
1813 MONGOCXX_PRIVATE stdx::optional<result::insert_many> _insert_many(
1814 const client_session* session,
1815 document_view_iterator_type begin,
1816 document_view_iterator_type end,
1817 const options::insert& options);
1818
1819 class MONGOCXX_PRIVATE impl;
1820
1821 MONGOCXX_PRIVATE impl& _get_impl();
1822 MONGOCXX_PRIVATE const impl& _get_impl() const;
1823
1824 std::unique_ptr<impl> _impl;
1825};
1826
1827MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1828 const model::write& write, const options::bulk_write& options) {
1829 return create_bulk_write(options).append(write).execute();
1830}
1831
1832MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::write(
1833 const client_session& session, const model::write& write, const options::bulk_write& options) {
1834 return create_bulk_write(session, options).append(write).execute();
1835}
1836
1837template <typename container_type>
1838MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1839 const container_type& requests, const options::bulk_write& options) {
1840 return bulk_write(requests.begin(), requests.end(), options);
1841}
1842
1843template <typename container_type>
1844MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1845 const client_session& session,
1846 const container_type& requests,
1847 const options::bulk_write& options) {
1848 return bulk_write(session, requests.begin(), requests.end(), options);
1849}
1850
1851template <typename write_model_iterator_type>
1852MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1853 write_model_iterator_type begin,
1854 write_model_iterator_type end,
1855 const options::bulk_write& options) {
1856 auto writes = create_bulk_write(options);
1857 std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
1858 return writes.execute();
1859}
1860
1861template <typename write_model_iterator_type>
1862MONGOCXX_INLINE stdx::optional<result::bulk_write> collection::bulk_write(
1863 const client_session& session,
1864 write_model_iterator_type begin,
1865 write_model_iterator_type end,
1866 const options::bulk_write& options) {
1867 auto writes = create_bulk_write(session, options);
1868 std::for_each(begin, end, [&](const model::write& current) { writes.append(current); });
1869 return writes.execute();
1870}
1871
1872template <typename container_type>
1873MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
1874 const container_type& container, const options::insert& options) {
1875 return insert_many(container.begin(), container.end(), options);
1876}
1877
1878template <typename container_type>
1879MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
1880 const client_session& session,
1881 const container_type& container,
1882 const options::insert& options) {
1883 return insert_many(session, container.begin(), container.end(), options);
1884}
1885
1886template <typename document_view_iterator_type>
1887MONGOCXX_INLINE stdx::optional<result::insert_many> collection::_insert_many(
1888
1889 const client_session* session,
1890 document_view_iterator_type begin,
1891 document_view_iterator_type end,
1892 const options::insert& options) {
1893 bsoncxx::builder::basic::array inserted_ids;
1894 auto writes = _init_insert_many(options, session);
1895 std::for_each(begin, end, [&inserted_ids, &writes, this](bsoncxx::document::view doc) {
1896 _insert_many_doc_handler(writes, inserted_ids, doc);
1897 });
1898 return _exec_insert_many(writes, inserted_ids);
1899}
1900
1901template <typename document_view_iterator_type>
1902MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
1903 document_view_iterator_type begin,
1904 document_view_iterator_type end,
1905 const options::insert& options) {
1906 return _insert_many(nullptr, begin, end, options);
1907}
1908
1909template <typename document_view_iterator_type>
1910MONGOCXX_INLINE stdx::optional<result::insert_many> collection::insert_many(
1911 const client_session& session,
1912 document_view_iterator_type begin,
1913 document_view_iterator_type end,
1914 const options::insert& options) {
1915 return _insert_many(&session, begin, end, options);
1916}
1917
1918MONGOCXX_INLINE_NAMESPACE_END
1919} // namespace mongocxx
1920
1921#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:33
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
Definition change_stream.hpp:31
Use a session for a sequence of operations, optionally with causal consistency.
Definition client_session.hpp:38
Class representing server side document groupings within a MongoDB database.
Definition collection.hpp:85
collection() noexcept
Default constructs a collection object.
stdx::optional< result::replace_one > replace_one(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const T &options)
Replaces a single document matching the provided filter in this collection.
Definition collection.hpp:1423
void write_concern(class write_concern wc)
Sets the write_concern for this collection.
stdx::optional< result::replace_one > replace_one_deprecated(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::update &options)
Replaces a single document matching the provided filter in this collection.
stdx::optional< bsoncxx::document::value > find_one_and_replace(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::find_one_and_replace &options=options::find_one_and_replace())
Finds a single document matching the filter, replaces it, and returns either the original or the repl...
stdx::optional< result::replace_one > replace_one(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::replace &options=options::replace{})
Replaces a single document matching the provided filter in this collection.
stdx::optional< result::replace_one > replace_one(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::replace &options=options::replace{})
Replaces a single document matching the provided filter in this collection.
change_stream watch(const options::change_stream &options={})
Gets a change stream on this collection with an empty pipeline.
stdx::optional< bsoncxx::document::value > find_one_and_update(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
index_view indexes()
Gets an index_view to the collection.
stdx::optional< result::insert_one > insert_one(const client_session &session, bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
stdx::optional< result::delete_result > delete_many(const client_session &session, bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes all matching documents from the collection.
std::int64_t count_deprecated(const client_session &session, bsoncxx::document::view_or_value filter, const options::count &options=options::count())
Counts the number of documents matching the provided filter.
stdx::optional< bsoncxx::document::value > find_one(const client_session &session, bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds a single document in this collection that match the provided filter.
stdx::optional< bsoncxx::document::value > find_one_and_update(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::find_one_and_update &options=options::find_one_and_update())
Finds a single document matching the filter, updates it, and returns either the original or the newly...
void rename(bsoncxx::string::view_or_value new_name, bool drop_target_before_rename=false, const bsoncxx::stdx::optional< write_concern > &write_concern={})
Rename this collection.
bsoncxx::document::value create_index(bsoncxx::document::view_or_value keys, bsoncxx::document::view_or_value index_options={}, options::index_view operation_options=options::index_view{})
Creates an index over the collection for the provided keys with the provided options.
std::int64_t count_deprecated(bsoncxx::document::view_or_value filter, const options::count &options=options::count())
Counts the number of documents matching the provided filter.
stdx::optional< result::update > update_one(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.
cursor distinct(bsoncxx::string::view_or_value name, bsoncxx::document::view_or_value filter, const options::distinct &options=options::distinct())
Finds the distinct values for a specified field across the collection.
cursor list_indexes() const
Returns a list of the indexes currently on this collection.
void read_preference(class read_preference rp)
Sets the read_preference for this collection.
stdx::optional< bsoncxx::document::value > find_one_and_delete(const client_session &session, bsoncxx::document::view_or_value filter, const options::find_one_and_delete &options=options::find_one_and_delete())
Finds a single document matching the filter, deletes it, and returns the original.
std::int64_t estimated_document_count(const options::estimated_document_count &options=options::estimated_document_count())
Returns an estimate of the number of documents in the collection.
stdx::optional< bsoncxx::document::value > find_one_and_delete(bsoncxx::document::view_or_value filter, const options::find_one_and_delete &options=options::find_one_and_delete())
Finds a single document matching the filter, deletes it, and returns the original.
change_stream watch(const client_session &session, const options::change_stream &options={})
change_stream watch(const client_session &session, const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
void rename(const client_session &session, bsoncxx::string::view_or_value new_name, bool drop_target_before_rename=false, const bsoncxx::stdx::optional< write_concern > &write_concern={})
Rename this collection.
stdx::optional< result::delete_result > delete_one(bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes a single matching document from the collection.
std::int64_t count_documents(bsoncxx::document::view_or_value filter, const options::count &options=options::count())
Counts the number of documents matching the provided filter.
stdx::optional< bsoncxx::document::value > find_one_and_replace(bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::find_one_and_replace &options=options::find_one_and_replace())
Finds a single document matching the filter, replaces it, and returns either the original or the repl...
cursor distinct(const client_session &session, bsoncxx::string::view_or_value name, bsoncxx::document::view_or_value filter, const options::distinct &options=options::distinct())
Finds the distinct values for a specified field across the collection.
stdx::optional< result::delete_result > delete_one(const client_session &session, bsoncxx::document::view_or_value filter, const options::delete_options &options=options::delete_options())
Deletes a single matching document from the collection.
std::int64_t count_documents(const client_session &session, bsoncxx::document::view_or_value filter, const options::count &options=options::count())
Counts the number of documents matching the provided filter.
void drop(const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops this collection and all its contained documents from the database.
std::int64_t count(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(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< result::replace_one > replace_one(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const T &options)
Replaces a single document matching the provided filter in this collection.
Definition collection.hpp:1463
bsoncxx::document::value create_index(const client_session &session, bsoncxx::document::view_or_value keys, bsoncxx::document::view_or_value index_options={}, options::index_view operation_options=options::index_view{})
Creates an index over the collection for the provided keys with the provided options.
change_stream watch(const pipeline &pipe, const options::change_stream &options={})
Gets a change stream on this collection.
void read_concern(class read_concern rc)
Sets the read_concern for this collection.
stdx::optional< bsoncxx::document::value > find_one(bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds a single document in this collection that match the provided filter.
stdx::optional< result::update > update_one(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value update, const options::update &options=options::update())
Updates a single document matching the provided filter in this collection.
void drop(const client_session &session, const bsoncxx::stdx::optional< mongocxx::write_concern > &write_concern={})
Drops this collection and all its contained documents from the database.
cursor find(const client_session &session, bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds the documents in this collection which match the provided filter.
stdx::optional< result::replace_one > replace_one_deprecated(const client_session &session, bsoncxx::document::view_or_value filter, bsoncxx::document::view_or_value replacement, const options::update &options)
Replaces a single document matching the provided filter in this collection.
cursor find(bsoncxx::document::view_or_value filter, const options::find &options=options::find())
Finds the documents in this collection which match the provided filter.
stdx::string_view name() const
Returns the name of this collection.
std::int64_t count(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::insert_one > insert_one(bsoncxx::document::view_or_value document, const options::insert &options={})
Inserts a single document into the collection.
cursor list_indexes(const client_session &session) const
Returns a list of the indexes currently on this collection.
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:36
Class representing a MongoDB database.
Definition database.hpp:44
Definition index_view.hpp:32
Class representing a MongoDB update operation that replaces a single document.
Definition replace_one.hpp:30
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:36
Class representing the optional arguments to a MongoDB bulk write.
Definition bulk_write.hpp:29
Definition change_stream.hpp:35
Class representing the optional arguments to mongocxx::collection::count_documents.
Definition count.hpp:36
Class representing the optional arguments to a MongoDB delete operation.
Definition delete.hpp:30
Class representing the optional arguments to a MongoDB distinct command.
Definition distinct.hpp:34
Class representing the optional arguments to mongocxx::collection::estimated_document_count.
Definition estimated_document_count.hpp:32
Class representing the optional arguments to a MongoDB find_and_modify delete operation.
Definition find_one_and_delete.hpp:33
Class representing the optional arguments to a MongoDB find_and_modify replace operation.
Definition find_one_and_replace.hpp:35
Class representing the optional arguments to a MongoDB find_and_modify update operation.
Definition find_one_and_update.hpp:36
Class representing the optional arguments to a MongoDB query.
Definition find.hpp:36
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:31
Class representing the optional arguments to a MongoDB replace operation.
Definition replace.hpp:32
Class representing the optional arguments to a MongoDB update operation.
Definition update.hpp:32
Class representing a MongoDB aggregation pipeline.
Definition pipeline.hpp:37
A class to represent the read concern.
Definition read_concern.hpp:53
Class representing a preference for how the driver routes read operations to members of a replica set...
Definition read_preference.hpp:62
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