MongoDB C++ Driver 4.4.0
Loading...
Searching...
No Matches
count.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/count-fwd.hpp> // IWYU pragma: export
18
19//
20
23
24#include <mongocxx/v1/count_options.hpp> // IWYU pragma: export
25
26#include <chrono>
27#include <cstdint>
28#include <string> // IWYU pragma: keep: backward compatibility, to be removed.
29#include <utility>
30
36
37#include <mongocxx/hint.hpp>
40
42
43namespace mongocxx {
44namespace v_noabi {
45namespace options {
46
50class count {
51 public:
55 count() = default;
56
61
65 explicit operator v1::count_options() const {
68
70
71 if (_collation) {
72 ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
73 }
74
75 if (_hint) {
76 ret.hint(to_v1(*_hint));
77 }
78
79 if (_comment) {
80 ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
81 }
82
83 if (_limit) {
84 ret.limit(*_limit);
85 }
86
87 if (_max_time) {
88 ret.max_time(*_max_time);
89 }
90
91 if (_skip) {
92 ret.skip(*_skip);
93 }
94
95 if (_read_preference) {
96 ret.read_preference(to_v1(*_read_preference));
97 }
98
99 if (_read_concern) {
100 ret.read_concern(to_v1(*_read_concern));
101 }
102
103 return ret;
104 }
105
120 _collation = std::move(collation);
121 return *this;
122 }
123
136
150 count& hint(v_noabi::hint index_hint) {
151 _hint = std::move(index_hint);
152 return *this;
153 }
154
164 return _hint;
165 }
166
181 _comment = std::move(comment);
182 return *this;
183 }
184
196
210 count& limit(std::int64_t limit) {
211 _limit = limit;
212 return *this;
213 }
214
224 return _limit;
225 }
226
240 count& max_time(std::chrono::milliseconds max_time) {
241 _max_time = max_time;
242 return *this;
243 }
244
254 return _max_time;
255 }
256
270 count& skip(std::int64_t skip) {
271 _skip = skip;
272 return *this;
273 }
274
284 return _skip;
285 }
286
301 _read_preference = std::move(rp);
302 return *this;
303 }
304
314 return _read_preference;
315 }
316
331 _read_concern = std::move(rc);
332 return *this;
333 }
334
345 return _read_concern;
346 }
347
348 private:
357};
358
359} // namespace options
360} // namespace v_noabi
361} // namespace mongocxx
362
363namespace mongocxx {
364namespace v_noabi {
365
370 return {std::move(v)};
371}
372
379
380} // namespace v_noabi
381} // namespace mongocxx
382
384
A BSON document.
Definition value.hpp:44
A polyfill for std::optional<T>.
Definition optional.hpp:799
A union of BSON type values.
Definition value.hpp:52
count()=default
Default initialization.
Options for a "countDocuments" operation.
Definition count_options.hpp:58
count_options & skip(std::int64_t v)
Set the "skip" field.
count_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
count_options & read_preference(v1::read_preference v)
Set the "readPreference" field.
count_options & limit(std::int64_t v)
Set the "limit" field.
count_options & read_concern(v1::read_concern v)
Set the "readConcern" field.
count_options & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
count_options & max_time(std::chrono::milliseconds v)
Set the "maxTimeMS" field.
count_options & hint(v1::hint v)
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 mongocxx::v_noabi::collection::count_documents.
Definition count.hpp:50
bsoncxx::v_noabi::stdx::optional< v_noabi::read_preference > const & read_preference() const
The current read_preference for this operation.
Definition count.hpp:313
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & collation() const
Retrieves the current collation for this operation.
Definition count.hpp:133
count & read_preference(v_noabi::read_preference rp)
Sets the read_preference for this operation.
Definition count.hpp:300
bsoncxx::v_noabi::stdx::optional< v_noabi::read_concern > const & read_concern() const
The current read_concern for this operation.
Definition count.hpp:344
count & skip(std::int64_t skip)
Sets the number of documents to skip before counting documents.
Definition count.hpp:270
count & max_time(std::chrono::milliseconds max_time)
Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
Definition count.hpp:240
count & limit(std::int64_t limit)
Sets the maximum number of documents to count.
Definition count.hpp:210
bsoncxx::v_noabi::stdx::optional< std::chrono::milliseconds > const & max_time() const
The current max_time setting.
Definition count.hpp:253
count()=default
Default initialization.
bsoncxx::v_noabi::stdx::optional< std::int64_t > const & limit() const
Gets the current limit.
Definition count.hpp:223
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::types::bson_value::view_or_value > const & comment() const
Gets the current value of the comment option.
Definition count.hpp:193
count & comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment)
Set the value of the comment option.
Definition count.hpp:180
count & hint(v_noabi::hint index_hint)
Sets the index to use for this operation.
Definition count.hpp:150
bsoncxx::v_noabi::stdx::optional< v_noabi::hint > const & hint() const
Gets the current hint.
Definition count.hpp:163
operator v1::count_options() const
Convert to the mongocxx::v1 equivalent.
Definition count.hpp:65
bsoncxx::v_noabi::stdx::optional< std::int64_t > const & skip() const
Gets the current number of documents to skip.
Definition count.hpp:283
count & read_concern(v_noabi::read_concern rc)
Sets the read_concern for this operation.
Definition count.hpp:330
count & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this operation.
Definition count.hpp:119
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
Declares mongocxx::v_noabi::options::count.
Provides mongocxx::v1::count_options.
Provides bsoncxx::v_noabi::document::view_or_value.
#define MONGOCXX_ABI_EXPORT_CDECL_UNSTABLE(...)
Equivalent to MONGOCXX_ABI_EXPORT_UNSTABLE with MONGOCXX_ABI_CDECL.
Definition config.hpp:28
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::types::bson_value::view_or_value.
Provides bsoncxx::v1::document::value.
Provides bsoncxx::v1::types::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Provides bsoncxx::v_noabi::types::bson_value::view.
Provides mongocxx::v_noabi::hint.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::read_preference.