MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
aggregate.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/aggregate-fwd.hpp> // IWYU pragma: export
18
19//
20
23
24#include <mongocxx/v1/aggregate_options.hpp> // IWYU pragma: export
25
26#include <chrono>
27#include <cstdint>
28#include <utility>
29
30#include <mongocxx/collection-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
31#include <mongocxx/database-fwd.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
32
33#include <bsoncxx/builder/basic/document.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
39
40#include <mongocxx/hint.hpp>
44
46
47namespace mongocxx {
48namespace v_noabi {
49namespace options {
50
54class aggregate {
55 public:
59 aggregate() = default;
60
65
69 explicit operator v1::aggregate_options() const {
72
74
75 if (_allow_disk_use) {
76 ret.allow_disk_use(*_allow_disk_use);
77 }
78
79 if (_batch_size) {
80 ret.batch_size(*_batch_size);
81 }
82
83 if (_collation) {
84 ret.collation(bsoncxx::v1::document::value{to_v1(_collation->view())});
85 }
86
87 if (_let) {
88 ret.let(bsoncxx::v1::document::value{to_v1(_let->view())});
89 }
90
91 if (_max_time) {
92 ret.max_time(*_max_time);
93 }
94
95 if (_read_preference) {
96 ret.read_preference(to_v1(*_read_preference));
97 }
98
99 if (_bypass_document_validation) {
100 ret.bypass_document_validation(*_bypass_document_validation);
101 }
102
103 if (_hint) {
104 ret.hint(to_v1(*_hint));
105 }
106
107 if (_write_concern) {
108 ret.write_concern(to_v1(*_write_concern));
109 }
110
111 if (_read_concern) {
112 ret.read_concern(to_v1(*_read_concern));
113 }
114
115 if (_comment) {
116 ret.comment(bsoncxx::v1::types::value{to_v1(_comment->view())});
117 }
118
119 return ret;
120 }
121
137 _allow_disk_use = allow_disk_use;
138 return *this;
139 }
140
150 return _allow_disk_use;
151 }
152
167 _batch_size = batch_size;
168 return *this;
169 }
170
180 return _batch_size;
181 }
182
197 _collation = std::move(collation);
198 return *this;
199 }
200
213
228 _let = std::move(let);
229 return *this;
230 }
231
244
258 aggregate& max_time(std::chrono::milliseconds max_time) {
259 _max_time = max_time;
260 return *this;
261 }
262
273 return _max_time;
274 }
275
289 _read_preference = std::move(rp);
290 return *this;
291 }
292
302 return _read_preference;
303 }
304
315 _bypass_document_validation = bypass_document_validation;
316 return *this;
317 }
318
328 return _bypass_document_validation;
329 }
330
348 _hint = std::move(index_hint);
349 return *this;
350 }
351
361 return _hint;
362 }
363
379 _write_concern = std::move(write_concern);
380 return *this;
381 }
382
393 return _write_concern;
394 }
395
409 _read_concern = std::move(read_concern);
410 return *this;
411 }
412
423 return _read_concern;
424 }
425
439 _comment = std::move(comment);
440 return *this;
441 }
442
455
456 class internal;
457
458 private:
465 bsoncxx::v_noabi::stdx::optional<bool> _bypass_document_validation;
470};
471
472} // namespace options
473} // namespace v_noabi
474} // namespace mongocxx
475
476namespace mongocxx {
477namespace v_noabi {
478
483 return {std::move(v)};
484}
485
492
493} // namespace v_noabi
494} // namespace mongocxx
495
497
Declares mongocxx::v_noabi::options::aggregate.
Provides mongocxx::v1::aggregate_options.
Provides bsoncxx::v_noabi::builder::basic::document.
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
aggregate()=default
Default initialization.
Options for an "aggregate" command.
Definition aggregate_options.hpp:64
aggregate_options & allow_disk_use(bool allow_disk_use)
Set the "allowDiskUse" field.
aggregate_options & write_concern(v1::write_concern write_concern)
Set the "writeConcern" field.
aggregate_options & max_time(std::chrono::milliseconds max_time)
Set the "maxTimeMS" field.
aggregate_options & hint(v1::hint index_hint)
Set the "hint" field.
aggregate_options & let(bsoncxx::v1::document::value let)
Set the "let" field.
aggregate_options & read_concern(v1::read_concern read_concern)
Set the "readConcern" field.
aggregate_options & read_preference(v1::read_preference rp)
Set the "readPreference" field.
aggregate_options & bypass_document_validation(bool bypass_document_validation)
Set the "bypassDocumentValidation" field.
aggregate_options & comment(bsoncxx::v1::types::value comment)
Set the "comment" field.
aggregate_options & batch_size(std::int32_t batch_size)
Set the "batchSize" field.
aggregate_options & collation(bsoncxx::v1::document::value collation)
Set the "collation" field.
The index to "hint" or force a MongoDB server to use when performing a query.
Definition hint.hpp:42
Used by MongoDB aggregation operations.
Definition aggregate.hpp:54
aggregate & let(bsoncxx::v_noabi::document::view_or_value let)
Sets the variable mapping for this operation.
Definition aggregate.hpp:227
aggregate & bypass_document_validation(bool bypass_document_validation)
Sets whether the $out stage should bypass document validation.
Definition aggregate.hpp:314
bsoncxx::v_noabi::stdx::optional< std::chrono::milliseconds > const & max_time() const
The current max_time setting.
Definition aggregate.hpp:272
bsoncxx::v_noabi::stdx::optional< v_noabi::hint > const & hint() const
Gets the current hint.
Definition aggregate.hpp:360
bsoncxx::v_noabi::stdx::optional< bool > const & allow_disk_use() const
Retrieves the current allow_disk_use setting.
Definition aggregate.hpp:149
bsoncxx::v_noabi::stdx::optional< std::int32_t > const & batch_size() const
The current batch size setting.
Definition aggregate.hpp:179
bsoncxx::v_noabi::stdx::optional< v_noabi::read_concern > const & read_concern() const
Gets the current read concern.
Definition aggregate.hpp:422
aggregate & max_time(std::chrono::milliseconds max_time)
Sets the maximum amount of time for this operation to run server-side in milliseconds.
Definition aggregate.hpp:258
aggregate & batch_size(std::int32_t batch_size)
Sets the number of documents to return per batch.
Definition aggregate.hpp:166
aggregate()=default
Default initialization.
bsoncxx::v_noabi::stdx::optional< v_noabi::read_preference > const & read_preference() const
The current read_preference for this operation.
Definition aggregate.hpp:301
aggregate & read_preference(v_noabi::read_preference rp)
Sets the read_preference for this operation.
Definition aggregate.hpp:288
aggregate & comment(bsoncxx::v_noabi::types::bson_value::view_or_value comment)
Sets the comment to use for this operation.
Definition aggregate.hpp:438
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & let() const
Retrieves the current variable mapping for this operation.
Definition aggregate.hpp:241
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::types::bson_value::view_or_value > const & comment() const
Gets the current comment.
Definition aggregate.hpp:452
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view_or_value > const & collation() const
Retrieves the current collation for this operation.
Definition aggregate.hpp:210
aggregate & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this operation.
Definition aggregate.hpp:196
operator v1::aggregate_options() const
Convert to the mongocxx::v1 equivalent.
Definition aggregate.hpp:69
bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & write_concern() const
Gets the current write concern.
Definition aggregate.hpp:392
aggregate & hint(v_noabi::hint index_hint)
Sets the index to use for this operation.
Definition aggregate.hpp:347
aggregate & write_concern(v_noabi::write_concern write_concern)
Sets the write concern to use for this operation. Only has an effect if $out is a part of the pipelin...
Definition aggregate.hpp:378
bsoncxx::v_noabi::stdx::optional< bool > const & bypass_document_validation() const
The current bypass_document_validation setting.
Definition aggregate.hpp:327
aggregate & allow_disk_use(bool allow_disk_use)
Enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp s...
Definition aggregate.hpp:136
aggregate & read_concern(v_noabi::read_concern read_concern)
Sets the read concern to use for this operation.
Definition aggregate.hpp:408
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
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
Provides bsoncxx::v_noabi::document::view_or_value.
#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::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.
Declares mongocxx::v_noabi::collection.
Declares mongocxx::v_noabi::database.
Provides mongocxx::v_noabi::hint.
Provides mongocxx::v_noabi::read_concern.
Provides mongocxx::v_noabi::read_preference.
Provides mongocxx::v_noabi::write_concern.