MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
index_view.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/index_view-fwd.hpp> // IWYU pragma: export
18
19//
20
22
23#include <mongocxx/v1/indexes.hpp> // IWYU pragma: export
24
25#include <chrono>
26#include <cstdint>
27#include <string>
28#include <utility>
29
33
35
37
38namespace mongocxx {
39namespace v_noabi {
40namespace options {
41
46 public:
50 index_view() = default;
51
56 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() index_view(v1::indexes::create_one_options opts);
57 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() index_view(v1::indexes::create_many_options opts);
60
65 explicit operator v1::indexes::create_many_options() const {
67 using v_noabi::to_v1;
68
70
71 if (_max_time) {
72 ret.max_time(*_max_time);
73 }
74
75 if (_write_concern) {
76 ret.write_concern(to_v1(*_write_concern));
77 }
78
79 if (_commit_quorum) {
80 ret.commit_quorum(bsoncxx::v1::document::value{to_v1(_commit_quorum->view())});
81 }
82
83 return ret;
84 }
85
86 explicit operator v1::indexes::create_one_options() const {
88 using v_noabi::to_v1;
89
91
92 if (_max_time) {
93 ret.max_time(*_max_time);
94 }
95
96 if (_write_concern) {
97 ret.write_concern(to_v1(*_write_concern));
98 }
99
100 if (_commit_quorum) {
101 ret.commit_quorum(bsoncxx::v1::document::value{to_v1(_commit_quorum->view())});
102 }
103
104 return ret;
105 }
106
108
122 index_view& max_time(std::chrono::milliseconds max_time) {
123 _max_time = max_time;
124 return *this;
125 }
126
137 return _max_time;
138 }
139
154 _write_concern = std::move(write_concern);
155 return *this;
156 }
157
168 return _write_concern;
169 }
170
189
208
223
224 private:
228};
229
230} // namespace options
231} // namespace v_noabi
232} // namespace mongocxx
233
234namespace mongocxx {
235namespace v_noabi {
236
243
248 return {std::move(v)};
249}
250
251// Ambiguous whether `v_noabi::options::index_view` should be converted to `v1::indexes::create_many_options` or
252// `v1::indexes::create_one_options`. Require users to explicitly cast to the expected type instead.
253//
254// v1::indexes::create_many_options to_v1(v_noabi::options::index_view const& v);
255// v1::indexes::create_one_options to_v1(v_noabi::options::index_view const& v);
256
257} // namespace v_noabi
258} // namespace mongocxx
259
261
A BSON document.
Definition value.hpp:46
A polyfill for std::optional<T>.
Definition optional.hpp:799
index_view()=default
Default initialization.
Options for mongocxx::v1::indexes::create_many.
Definition indexes.hpp:536
create_many_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
create_many_options & commit_quorum(bsoncxx::v1::document::value v)
Set the "commitQuorum" field.
create_many_options & max_time(std::chrono::milliseconds v)
Set the "maxTimeMS" field.
Options for mongocxx::v1::indexes::create_one.
Definition indexes.hpp:435
create_one_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
create_one_options & commit_quorum(bsoncxx::v1::document::value v)
Set the "commitQuorum" field.
create_one_options & max_time(std::chrono::milliseconds v)
Set the "maxTimeMS" field.
Used by MongoDB index view operations.
Definition index_view.hpp:45
bsoncxx::v_noabi::stdx::optional< v_noabi::write_concern > const & write_concern() const
Gets the current write concern.
Definition index_view.hpp:167
index_view & commit_quorum(std::string commit_quorum)
Sets the commit quorum for this operation.
operator v1::indexes::create_many_options() const
Convert to the mongocxx::v1 equivalent.
Definition index_view.hpp:65
index_view & commit_quorum(std::int32_t commit_quorum)
Sets the commit quorum for this operation.
operator v1::indexes::create_one_options() const
Convert to the mongocxx::v1 equivalent.
Definition index_view.hpp:86
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::value > const commit_quorum() const
Gets the current commitQuorum setting.
Definition index_view.hpp:220
index_view & write_concern(v_noabi::write_concern write_concern)
Sets the write concern for this operation.
Definition index_view.hpp:153
bsoncxx::v_noabi::stdx::optional< std::chrono::milliseconds > const & max_time() const
The current max_time setting.
Definition index_view.hpp:136
index_view & max_time(std::chrono::milliseconds max_time)
Sets the maximum amount of time for this operation to run (server-side) in milliseconds.
Definition index_view.hpp:122
index_view()=default
Default initialization.
The level of acknowledgment requested for write operations to a MongoDB server.
Definition write_concern.hpp:54
Provides mongocxx::v1::indexes.
#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.
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.
Declares mongocxx::v_noabi::options::index_view.
Provides bsoncxx::v1::document::value.
Provides bsoncxx::v_noabi::document::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Provides mongocxx::v_noabi::write_concern.