MongoDB C++ Driver 4.3.0
Loading...
Searching...
No Matches
find.hpp
Go to the documentation of this file.
1// Copyright 2009-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 <mongocxx/options/find-fwd.hpp> // IWYU pragma: export
18
19//
20
22
24#include <mongocxx/v1/find_options.hpp> // IWYU pragma: export
25
26#include <chrono>
27#include <cstdint>
28#include <utility>
29
37
38#include <mongocxx/cursor.hpp>
39#include <mongocxx/hint.hpp>
42
44
45namespace mongocxx {
46namespace v_noabi {
47namespace options {
48
52class find {
53 public:
57 find() = default;
58
62 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() find(v1::find_options opts);
63
70 explicit operator v1::find_options() const {
73
75
76 if (_allow_disk_use) {
77 ret.allow_disk_use(*_allow_disk_use);
78 }
79
80 if (_allow_partial_results) {
81 ret.allow_partial_results(*_allow_partial_results);
82 }
83
84 if (_batch_size) {
85 ret.batch_size(*_batch_size);
86 }
87
88 if (_collation) {
89 ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
90 }
91
92 if (_cursor_type) {
93 ret.cursor_type(static_cast<v1::cursor::type>(*_cursor_type));
94 }
95
96 if (_hint) {
97 ret.hint(to_v1(*_hint));
98 }
99
100 if (_let) {
101 ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
102 }
103
104 if (_comment_option) {
105 ret.comment(bsoncxx::v1::types::value{to_v1(_comment_option->view())});
106 } else if (_comment) {
107 ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
108 }
109
110 if (_limit) {
111 ret.limit(*_limit);
112 }
113
114 if (_max) {
115 ret.max(bsoncxx::v1::document::value{to_v1(_max->view())});
116 }
117
118 if (_max_await_time) {
119 ret.max_await_time(*_max_await_time);
120 }
121
122 if (_max_time) {
123 ret.max_time(*_max_time);
124 }
125
126 if (_min) {
127 ret.min(bsoncxx::v1::document::value{to_v1(_min->view())});
128 }
129
130 if (_no_cursor_timeout) {
131 ret.no_cursor_timeout(*_no_cursor_timeout);
132 }
133
134 if (_projection) {
135 ret.projection(bsoncxx::v1::document::value{to_v1(_projection->view())});
136 }
137
138 if (_read_preference) {
139 ret.read_preference(to_v1(*_read_preference));
140 }
141
142 if (_read_concern) {
143 ret.read_concern(to_v1(*_read_concern));
144 }
145
146 if (_return_key) {
147 ret.return_key(*_return_key);
148 }
149
150 if (_show_record_id) {
151 ret.show_record_id(*_show_record_id);
152 }
153
154 if (_skip) {
155 ret.skip(*_skip);
156 }
157
158 if (_ordering) {
159 ret.sort(bsoncxx::v1::document::value{to_v1(_ordering->view())});
160 }
161
162 return ret;
163 }
164
184 _allow_disk_use = allow_disk_use;
185 return *this;
186 }
187
196 return _allow_disk_use;
197 }
198
213 find& allow_partial_results(bool allow_partial) {
214 _allow_partial_results = allow_partial;
215 return *this;
216 }
217
227 return _allow_partial_results;
228 }
229
243 find& batch_size(std::int32_t batch_size) {
244 _batch_size = batch_size;
245 return *this;
246 }
247
257 return _batch_size;
258 }
259
274 _collation = std::move(collation);
275 return *this;
276 }
277
290
308 _comment = std::move(comment);
309 return *this;
310 }
311
325
339 find& cursor_type(cursor::type cursor_type) {
340 _cursor_type = cursor_type;
341 return *this;
342 }
343
353 return _cursor_type;
354 }
355
372 find& hint(v_noabi::hint index_hint) {
373 _hint = std::move(index_hint);
374 return *this;
375 }
376
386 return _hint;
387 }
388
403 _let = std::move(let);
404 return *this;
405 }
406
419
436 _comment_option = std::move(comment);
437 return *this;
438 }
439
454
467 find& limit(std::int64_t limit) {
468 _limit = limit;
469 return *this;
470 }
471
481 return _limit;
482 }
483
498 _max = std::move(max);
499 return *this;
500 }
501
513
532 find& max_await_time(std::chrono::milliseconds max_await_time) {
533 _max_await_time = max_await_time;
534 return *this;
535 }
536
547 return _max_await_time;
548 }
549
563 find& max_time(std::chrono::milliseconds max_time) {
564 _max_time = max_time;
565 return *this;
566 }
567
577 return _max_time;
578 }
579
594 _min = std::move(min);
595 return *this;
596 }
597
609
625 _no_cursor_timeout = no_cursor_timeout;
626 return *this;
627 }
628
638 return _no_cursor_timeout;
639 }
640
655 _projection = std::move(projection);
656 return *this;
657 }
658
670
685 _read_preference = std::move(rp);
686 return *this;
687 }
688
699 return _read_preference;
700 }
701
716 _read_concern = std::move(rc);
717 return *this;
718 }
719
730 return _read_concern;
731 }
732
749 _return_key = return_key;
750 return *this;
751 }
752
765 return _return_key;
766 }
767
782 _show_record_id = show_record_id;
783 return *this;
784 }
785
797 return _show_record_id;
798 }
799
813 find& skip(std::int64_t skip) {
814 _skip = skip;
815 return *this;
816 }
817
827 return _skip;
828 }
829
845 _ordering = std::move(ordering);
846 return *this;
847 }
848
860
861 private:
863 bsoncxx::v_noabi::stdx::optional<bool> _allow_partial_results;
884};
885
886} // namespace options
887} // namespace v_noabi
888} // namespace mongocxx
889
890namespace mongocxx {
891namespace v_noabi {
892
897 return {std::move(v)};
898}
899
904 return v1::find_options{v};
905}
906
907} // namespace v_noabi
908} // namespace mongocxx
909
911
A BSON document.
Definition value.hpp:46
A polyfill for std::optional<T>.
Definition optional.hpp:799
A union of BSON type values.
Definition value.hpp:54
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
find()=default
Default initialization.
type
Enumeration identifying the type of the cursor.
Definition cursor.hpp:50
Options for a "find" command.
Definition find_options.hpp:74
find_options & collation(bsoncxx::v1::document::value collation)
Set the "collation" field.
find_options & read_preference(v1::read_preference rp)
Set the "readPreference" field.
find_options & allow_partial_results(bool allow_partial)
Set the "allowPartialResults" field.
find_options & return_key(bool return_key)
Set the "returnKey" field.
find_options & batch_size(std::int32_t batch_size)
Set the "batchSize" field.
find_options & skip(std::int64_t skip)
Set the "skip" field.
find_options & comment(bsoncxx::v1::types::value comment)
Set the "comment" field.
find_options & min(bsoncxx::v1::document::value min)
Set the "min" field.
find_options & read_concern(v1::read_concern rc)
Set the "readConcern" field.
find_options & no_cursor_timeout(bool no_cursor_timeout)
Set the "noCursorTimeout" field.
find_options & allow_disk_use(bool allow_disk_use)
Set the "allowDiskUse" field.
find_options & show_record_id(bool show_record_id)
Set the "showRecordId" field.
find_options & cursor_type(v1::cursor::type cursor_type)
Set the "cursorType" field.
find_options & sort(bsoncxx::v1::document::value ordering)
Set the "sort" field.
find_options & limit(std::int64_t limit)
Set the "limit" field.
find_options & let(bsoncxx::v1::document::value let)
Set the "let" field.
find_options & max_await_time(std::chrono::milliseconds max_await_time)
Set the "maxAwaitTimeMS" field.
find_options & max_time(std::chrono::milliseconds max_time)
Set the "maxTimeMS" field.
find_options & max(bsoncxx::v1::document::value max)
Set the "max" field.
find_options & projection(bsoncxx::v1::document::value projection)
Set the "projection" field.
find_options & hint(v1::hint index_hint)
Set the "hint" field.
The index to "hint" or force a MongoDB server to use when performing a query.
Definition hint.hpp:42
Used by MongoDB find operations.
Definition find.hpp:52
find & read_concern(v_noabi::read_concern rc)
Sets the read_concern for this operation.
Definition find.hpp:715
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & collation() const
Retrieves the current collation for this operation.
Definition find.hpp:287
bsoncxx::v_noabi::stdx::optional< cursor::type > const & cursor_type() const
Gets the current cursor type.
Definition find.hpp:352
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & min() const
Sets the current inclusive lower bound for a specific index.
Definition find.hpp:606
find & sort(bsoncxx::v_noabi::document::view_or_value ordering)
The order in which to return matching documents. If $orderby also exists in the modifiers document,...
Definition find.hpp:844
find & let(bsoncxx::v_noabi::document::view_or_value let)
Set the value of the let option.
Definition find.hpp:402
find & max_await_time(std::chrono::milliseconds max_await_time)
The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query...
Definition find.hpp:532
bsoncxx::v_noabi::stdx::optional< v_noabi::hint > const & hint() const
Gets the current hint.
Definition find.hpp:385
find & return_key(bool return_key)
Sets whether to return the index keys associated with the query results, instead of the actual query ...
Definition find.hpp:748
find & comment_option(bsoncxx::v_noabi::types::bson_value::view_or_value comment)
Set the value of the comment option.
Definition find.hpp:435
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & sort() const
Gets the current sort ordering for this query.
Definition find.hpp:857
find & no_cursor_timeout(bool no_cursor_timeout)
Sets the cursor flag to prevent cursor from timing out server-side due to a period of inactivity.
Definition find.hpp:624
find & hint(v_noabi::hint index_hint)
Sets the index to use for this operation.
Definition find.hpp:372
find & allow_partial_results(bool allow_partial)
Sets whether to allow partial results from a mongos if some shards are down (instead of throwing an e...
Definition find.hpp:213
bsoncxx::v_noabi::stdx::optional< bool > const & allow_partial_results() const
Gets the current setting for allowing partial results from mongos.
Definition find.hpp:226
find()=default
Default initialization.
bsoncxx::v_noabi::stdx::optional< std::int64_t > const & limit() const
Gets the current limit.
Definition find.hpp:480
find & allow_disk_use(bool allow_disk_use)
Enables writing to temporary files on the server. When set to true, the server can write temporary da...
Definition find.hpp:183
find & limit(std::int64_t limit)
Sets maximum number of documents to return.
Definition find.hpp:467
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const let() const
Gets the current value of the let option.
Definition find.hpp:416
bsoncxx::v_noabi::stdx::optional< bool > const & show_record_id() const
Gets the current setting for whether the record identifier is returned for each document in the query...
Definition find.hpp:796
find & max_time(std::chrono::milliseconds max_time)
Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
Definition find.hpp:563
bsoncxx::v_noabi::stdx::optional< std::int32_t > const & batch_size() const
The current batch size setting.
Definition find.hpp:256
find & cursor_type(cursor::type cursor_type)
Indicates the type of cursor to use for this query.
Definition find.hpp:339
find & show_record_id(bool show_record_id)
Sets whether to include the record identifier for each document in the query results.
Definition find.hpp:781
find & min(bsoncxx::v_noabi::document::view_or_value min)
Gets the current inclusive lower bound for a specific index.
Definition find.hpp:593
bsoncxx::v_noabi::stdx::optional< bool > const & allow_disk_use() const
Gets the current setting for allowing disk use on the server.
Definition find.hpp:195
bsoncxx::v_noabi::stdx::optional< bool > const & no_cursor_timeout() const
Gets the current no_cursor_timeout setting.
Definition find.hpp:637
operator v1::find_options() const
Convert to the mongocxx::v1 equivalent.
Definition find.hpp:70
find & skip(std::int64_t skip)
Sets the number of documents to skip before returning results.
Definition find.hpp:813
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::types::bson_value::view_or_value > const & comment_option() const
Gets the current value of the comment option.
Definition find.hpp:451
find & comment(bsoncxx::v_noabi::string::view_or_value comment)
Attaches a comment to the query. If $comment also exists in the modifiers document then the comment f...
Definition find.hpp:307
bsoncxx::v_noabi::stdx::optional< std::int64_t > const & skip() const
Gets the current number of documents to skip.
Definition find.hpp:826
find & read_preference(v_noabi::read_preference rp)
Sets the read_preference for this operation.
Definition find.hpp:684
find & projection(bsoncxx::v_noabi::document::view_or_value projection)
Sets a projection which limits the returned fields for all matching documents.
Definition find.hpp:654
bsoncxx::v_noabi::stdx::optional< std::chrono::milliseconds > const & max_await_time() const
The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query...
Definition find.hpp:546
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & max() const
Sets the current exclusive upper bound for a specific index.
Definition find.hpp:510
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & comment() const
Gets the current comment attached to this query.
Definition find.hpp:322
find & max(bsoncxx::v_noabi::document::view_or_value max)
Gets the current exclusive upper bound for a specific index.
Definition find.hpp:497
bsoncxx::v_noabi::stdx::optional< std::chrono::milliseconds > const & max_time() const
The current max_time_ms setting.
Definition find.hpp:576
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & projection() const
Gets the current projection set on this query.
Definition find.hpp:667
find & batch_size(std::int32_t batch_size)
Sets the number of documents to return per batch.
Definition find.hpp:243
bsoncxx::v_noabi::stdx::optional< v_noabi::read_preference > const & read_preference() const
The current read_preference for this operation.
Definition find.hpp:698
bsoncxx::v_noabi::stdx::optional< bool > const & return_key() const
Gets the current setting for returning the index keys associated with the query results,...
Definition find.hpp:764
bsoncxx::v_noabi::stdx::optional< v_noabi::read_concern > const & read_concern() const
The current read_concern for this operation.
Definition find.hpp:729
find & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this operation.
Definition find.hpp:273
Controls the consistency and isolation properties of data read from replica sets and sharded clusters...
Definition read_concern.hpp:54
Describes how MongoDB clients route read operations to the members of a replica set or sharded cluste...
Definition read_preference.hpp:59
Provides bsoncxx::v_noabi::document::view_or_value.
Declares mongocxx::v_noabi::options::find.
Provides mongocxx::v1::find_options.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v_noabi macro guard postlude header.
The mongocxx v_noabi macro guard prelude header.
v_noabi::view_or_value< v_noabi::document::view, v_noabi::document::value > view_or_value
Equivalent to v_noabi::view_or_value<v_noabi::document::view, v_noabi::document::value>.
Definition view_or_value.hpp:30
v_noabi::view_or_value< view, value > view_or_value
Equivalent to v_noabi::view_or_value<view, value>.
Definition view_or_value.hpp:31
v1::element::view to_v1(v_noabi::array::element const &v)
Convert to the bsoncxx::v1 equivalent of v.
Definition element.hpp:132
Declares entities whose ABI stability is guaranteed for documented symbols.
Declares entities representing options to use with various commands.
Declares entities whose ABI stability is NOT guaranteed.
v1::bulk_write to_v1(v_noabi::bulk_write v)
Convert to the mongocxx::v1 equivalent of v.
Definition bulk_write.hpp:162
v_noabi::bulk_write from_v1(v1::bulk_write v)
Convert to the mongocxx::v_noabi equivalent of v.
Definition bulk_write.hpp:155
The top-level namespace within which all mongocxx library entities are declared.
Provides bsoncxx::v_noabi::string::view_or_value.
Provides bsoncxx::v_noabi::types::bson_value::view_or_value.
Provides mongocxx::v1::cursor.
Provides bsoncxx::v1::document::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Provides bsoncxx::v_noabi::types::bson_value::value.
Provides bsoncxx::v_noabi::types::bson_value::view.
Provides mongocxx::v_noabi::cursor.
Provides mongocxx::v_noabi::hint.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::read_preference.