MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
index.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-fwd.hpp> // IWYU pragma: export
18
19//
20
21#include <mongocxx/v1/indexes.hpp> // IWYU pragma: export
22
23#include <chrono>
24#include <cstdint>
25#include <memory>
26#include <string>
27#include <utility>
28
30
31#include <bsoncxx/document/value.hpp> // IWYU pragma: keep: backward compatibility, to be removed.
36
38
40
41namespace mongocxx {
42namespace v_noabi {
43namespace options {
44
51class index {
52 public:
53 BSONCXX_PRIVATE_WARNINGS_PUSH();
54 BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251));
55 BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275));
56
62 class MONGOCXX_ABI_EXPORT base_storage_options {
63 public:
64 virtual ~base_storage_options();
65
66 base_storage_options(base_storage_options&&) = default;
67 base_storage_options& operator=(base_storage_options&&) = default;
68 base_storage_options(base_storage_options const&) = default;
69 base_storage_options& operator=(base_storage_options const&) = default;
70
71 base_storage_options() = default;
72
73 private:
75
76 virtual int type() const = 0;
77 };
78
84 class MONGOCXX_ABI_EXPORT wiredtiger_storage_options final : public base_storage_options {
85 public:
86 ~wiredtiger_storage_options() override;
87
88 wiredtiger_storage_options(wiredtiger_storage_options&&) = default;
89 wiredtiger_storage_options& operator=(wiredtiger_storage_options&&) = default;
90 wiredtiger_storage_options(wiredtiger_storage_options const&) = default;
91 wiredtiger_storage_options& operator=(wiredtiger_storage_options const&) = default;
92
93 wiredtiger_storage_options() = default;
94
104
113
114 private:
115 friend v_noabi::collection;
116
117 MONGOCXX_ABI_NO_EXPORT int type() const override;
118
120 };
121
122 BSONCXX_PRIVATE_WARNINGS_POP();
123
127 index() = default;
128
134 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() index(v1::indexes::options const& opts);
135
141 explicit operator v1::indexes::options() const {
143
145
146 if (_background) {
147 ret.background(*_background);
148 }
149
150 if (_unique) {
151 ret.unique(*_unique);
152 }
153
154 if (_hidden) {
155 ret.hidden(*_hidden);
156 }
157
158 if (_name) {
159 ret.name(std::string{_name->view()});
160 }
161
162 if (_collation) {
164 }
165
166 if (_sparse) {
167 ret.sparse(*_sparse);
168 }
169
170 // _storage_options
171
172 if (_storage_engine) {
173 ret.storage_engine(bsoncxx::v1::document::value{to_v1(*_storage_engine)});
174 }
175
176 if (_expire_after) {
177 ret.expire_after(*_expire_after);
178 }
179
180 if (_version) {
181 ret.version(*_version);
182 }
183
184 if (_weights) {
186 }
187
188 if (_default_language) {
189 ret.default_language(std::string{_default_language->view()});
190 }
191
192 if (_language_override) {
193 ret.language_override(std::string{_language_override->view()});
194 }
195
196 if (_partial_filter_expression) {
197 ret.partial_filter_expression(bsoncxx::v1::document::value{to_v1(*_partial_filter_expression)});
198 }
199
200 if (_twod_sphere_version) {
201 ret.twod_sphere_version(*_twod_sphere_version);
202 }
203
204 if (_twod_bits_precision) {
205 ret.twod_bits_precision(*_twod_bits_precision);
206 }
207
208 if (_twod_location_min) {
209 ret.twod_location_min(*_twod_location_min);
210 }
211
212 if (_twod_location_max) {
213 ret.twod_location_max(*_twod_location_max);
214 }
215
216 // _haystack_bucket_size
217
218 return ret;
219 }
220
236 _background = std::move(background);
237 return *this;
238 }
239
246 return _background;
247 }
248
264 _unique = std::move(unique);
265 return *this;
266 }
267
274 return _unique;
275 }
276
292 _hidden = std::move(hidden);
293 return *this;
294 }
295
302 return _hidden;
303 }
304
316 _name = std::move(name);
317 return *this;
318 }
319
328
343 _collation = std::move(collation);
344 return *this;
345 }
346
359
375 _sparse = std::move(sparse);
376 return *this;
377 }
378
385 return _sparse;
386 }
387
402 MONGOCXX_DEPRECATED index& storage_options(std::unique_ptr<base_storage_options> storage_options) {
403 _storage_options = std::move(storage_options);
404 return *this;
405 }
406
417 MONGOCXX_DEPRECATED index& storage_options(std::unique_ptr<wiredtiger_storage_options> storage_options) {
418 _storage_options = std::move(storage_options);
419 return *this;
420 }
421
443
450
465 index& expire_after(std::chrono::seconds seconds) {
466 _expire_after = std::move(seconds);
467 return *this;
468 }
469
476 return _expire_after;
477 }
478
489 index& version(std::int32_t v) {
490 _version = std::move(v);
491 return *this;
492 }
493
500 return _version;
501 }
502
515 _weights = std::move(weights);
516 return *this;
517 }
518
527
540 _default_language = std::move(default_language);
541 return *this;
542 }
543
552
565 _language_override = std::move(language_override);
566 return *this;
567 }
568
577
589 _partial_filter_expression = std::move(partial_filter_expression);
590 return *this;
591 }
592
599 return _partial_filter_expression;
600 }
601
613 _twod_sphere_version = std::move(twod_sphere_version);
614 return *this;
615 }
616
623 return _twod_sphere_version;
624 }
625
637 _twod_bits_precision = std::move(twod_bits_precision);
638 return *this;
639 }
640
647 return _twod_bits_precision;
648 }
649
661 _twod_location_min = std::move(twod_location_min);
662 return *this;
663 }
664
671 return _twod_location_min;
672 }
673
685 _twod_location_max = std::move(twod_location_max);
686 return *this;
687 }
688
695 return _twod_location_max;
696 }
697
717 return this->haystack_bucket_size_deprecated(haystack_bucket_size);
718 }
719
720 index& haystack_bucket_size_deprecated(double haystack_bucket_size) {
721 _haystack_bucket_size = haystack_bucket_size;
722 return *this;
723 }
724
734 return this->haystack_bucket_size_deprecated();
735 }
736
737 bsoncxx::v_noabi::stdx::optional<double> const& haystack_bucket_size_deprecated() const {
738 return _haystack_bucket_size;
739 }
740
750
751 class internal;
752
753 private:
754 bsoncxx::v_noabi::stdx::optional<bool> _background;
755 bsoncxx::v_noabi::stdx::optional<bool> _unique;
756 bsoncxx::v_noabi::stdx::optional<bool> _hidden;
757 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::string::view_or_value> _name;
758 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> _collation;
759 bsoncxx::v_noabi::stdx::optional<bool> _sparse;
760 std::unique_ptr<base_storage_options> _storage_options;
761 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> _storage_engine;
762 bsoncxx::v_noabi::stdx::optional<std::chrono::seconds> _expire_after;
763 bsoncxx::v_noabi::stdx::optional<std::int32_t> _version;
764 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> _weights;
765 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::string::view_or_value> _default_language;
766 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::string::view_or_value> _language_override;
767 bsoncxx::v_noabi::stdx::optional<bsoncxx::v_noabi::document::view> _partial_filter_expression;
768 bsoncxx::v_noabi::stdx::optional<std::uint8_t> _twod_sphere_version;
769 bsoncxx::v_noabi::stdx::optional<std::uint8_t> _twod_bits_precision;
770 bsoncxx::v_noabi::stdx::optional<double> _twod_location_min;
771 bsoncxx::v_noabi::stdx::optional<double> _twod_location_max;
772 bsoncxx::v_noabi::stdx::optional<double> _haystack_bucket_size;
773};
774
775} // namespace options
776} // namespace v_noabi
777} // namespace mongocxx
778
779namespace mongocxx {
780namespace v_noabi {
781
786 return {v};
787}
788
795
796} // namespace v_noabi
797} // namespace mongocxx
798
800
802
The bsoncxx v_noabi macro guard postlude header.
The bsoncxx v_noabi macro guard prelude header.
A BSON document.
Definition value.hpp:46
A polyfill for std::optional<T>.
Definition optional.hpp:799
A read-only, non-owning view of a BSON document.
Definition view.hpp:40
A view-or-value variant type for strings.
Definition view_or_value.hpp:41
index()=default
Default initialization.
Options for mongocxx::v1::indexes::model.
Definition indexes.hpp:93
options & collation(bsoncxx::v1::document::value v)
Set the "collation" field.
options & twod_location_min(double v)
Set the "min" field.
options & default_language(std::string v)
Set the "default_language" field.
options & expire_after(std::chrono::seconds v)
Set the "expireAfterSeconds" field.
options & twod_location_max(double v)
Set the "max" field.
options & background(bool v)
Set the "background" field.
options & partial_filter_expression(bsoncxx::v1::document::value v)
Set the "partialFilterExpression" field.
options & language_override(std::string v)
Set the "language_override" field.
options & storage_engine(bsoncxx::v1::document::value v)
Set the "storageEngine" field.
options & version(std::int32_t v)
Set the "version" field.
options & twod_sphere_version(std::uint8_t v)
Set the "2dsphereIndexVersion" field.
options & sparse(bool v)
Set the "sparse" field.
options & weights(bsoncxx::v1::document::value v)
Set the "weights" field.
options & unique(bool v)
Set the "unique" field.
options & hidden(bool v)
Set the "hidden" field.
options & name(std::string v)
Set the "name" field.
options & twod_bits_precision(std::uint8_t v)
Set the "bits" field.
A MongoDB collection.
Definition collection.hpp:98
Base class representing the optional storage engine options for indexes.
Definition index.hpp:62
void config_string(bsoncxx::v_noabi::string::view_or_value config_string)
Set the WiredTiger configuration string.
Definition index.hpp:101
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & config_string() const
The current config_string setting.
Definition index.hpp:110
Used by MongoDB index creation operations.
Definition index.hpp:51
bsoncxx::v_noabi::stdx::optional< std::chrono::seconds > const & expire_after() const
The current expire_after setting.
Definition index.hpp:475
index & haystack_bucket_size(double haystack_bucket_size)
For geoHaystack indexes, specify the number of units within which to group the location values; i....
Definition index.hpp:716
index & hidden(bool hidden)
Whether or not the index is hidden from the query planner. A hidden index is not evaluated as part of...
Definition index.hpp:291
index & language_override(bsoncxx::v_noabi::string::view_or_value language_override)
For text indexes, the name of the field, in the collection’s documents, that contains the override la...
Definition index.hpp:564
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > const & weights() const
The current weights setting.
Definition index.hpp:524
operator v1::indexes::options() const
Convert to the mongocxx::v1 equivalent.
Definition index.hpp:141
index & twod_location_max(double twod_location_max)
For 2d indexes, the upper inclusive boundary for the longitude and latitude values.
Definition index.hpp:684
index & background(bool background)
Whether or not to build the index in the background so that building the index does not block other d...
Definition index.hpp:235
index & expire_after(std::chrono::seconds seconds)
Set a value, in seconds, as a TTL to control how long MongoDB retains documents in this collection.
Definition index.hpp:465
index & weights(bsoncxx::v_noabi::document::view weights)
For text indexes, sets the weight document. The weight document contains field and weight pairs.
Definition index.hpp:514
index & unique(bool unique)
Whether or not to create a unique index so that the collection will not accept insertion of documents...
Definition index.hpp:263
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > const & partial_filter_expression() const
The current partial_filter_expression setting.
Definition index.hpp:598
bsoncxx::v_noabi::stdx::optional< double > const & twod_location_min() const
The current lower inclusive boundary for the longitude and latitude values.
Definition index.hpp:670
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & language_override() const
The current name of the field that contains the override language for text indexes.
Definition index.hpp:574
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & name() const
The current name setting.
Definition index.hpp:325
bsoncxx::v_noabi::stdx::optional< double > const & haystack_bucket_size() const
The current haystack_bucket_size setting.
Definition index.hpp:733
index & storage_options(std::unique_ptr< base_storage_options > storage_options)
Specifies the storage engine options for the index.
Definition index.hpp:402
bsoncxx::v_noabi::stdx::optional< std::int32_t > const & version() const
The current index version.
Definition index.hpp:499
bsoncxx::v_noabi::stdx::optional< bool > const & sparse() const
The current sparse setting.
Definition index.hpp:384
index & collation(bsoncxx::v_noabi::document::view collation)
Sets the collation for this index.
Definition index.hpp:342
index & name(bsoncxx::v_noabi::string::view_or_value name)
The name of the index.
Definition index.hpp:315
bsoncxx::v_noabi::stdx::optional< std::uint8_t > const & twod_sphere_version() const
The current twod_sphere_version setting.
Definition index.hpp:622
index & storage_engine(bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > storage_engine)
Specifies the storage engine options for the index.
Definition index.hpp:439
index & version(std::int32_t v)
Sets the index version.
Definition index.hpp:489
bsoncxx::v_noabi::stdx::optional< bool > const & unique() const
The current unique setting.
Definition index.hpp:273
index & twod_location_min(double twod_location_min)
For 2d indexes, the lower inclusive boundary for the longitude and latitude values.
Definition index.hpp:660
index & default_language(bsoncxx::v_noabi::string::view_or_value default_language)
For text indexes, the language that determines the list of stop words and the rules for the stemmer a...
Definition index.hpp:539
index & twod_bits_precision(std::uint8_t twod_bits_precision)
For 2d indexes, the precision of the stored geohash value of the location data.
Definition index.hpp:636
index & storage_options(std::unique_ptr< wiredtiger_storage_options > storage_options)
Specifies the WiredTiger-specific storage engine options for the index.
Definition index.hpp:417
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > const & storage_engine() const
The current storage engine options.
Definition index.hpp:447
bsoncxx::v_noabi::stdx::optional< std::uint8_t > const & twod_bits_precision() const
The current precision of the stored geohash value of the location data.
Definition index.hpp:646
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::string::view_or_value > const & default_language() const
The current default_language setting.
Definition index.hpp:549
index()=default
Default initialization.
index & partial_filter_expression(bsoncxx::v_noabi::document::view partial_filter_expression)
Sets the document for the partial filter expression for partial indexes.
Definition index.hpp:588
bsoncxx::v_noabi::stdx::optional< double > const & twod_location_max() const
The current upper inclusive boundary for the longitude and latitude values.
Definition index.hpp:694
bsoncxx::v_noabi::stdx::optional< bool > const & background() const
The current background setting.
Definition index.hpp:245
bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > const & collation() const
Retrieves the current collation for this index.
Definition index.hpp:356
operator bsoncxx::v_noabi::document::view_or_value()
Conversion operator that provides a view of the options in document form.
index & twod_sphere_version(std::uint8_t twod_sphere_version)
For 2dsphere indexes, the 2dsphere index version number. Version can be either 1 or 2.
Definition index.hpp:612
index & sparse(bool sparse)
Whether or not to create a sparse index. Sparse indexes only reference documents with the indexed fie...
Definition index.hpp:374
bsoncxx::v_noabi::stdx::optional< bool > const & hidden() const
The current hidden setting.
Definition index.hpp:301
Provides bsoncxx::v_noabi::document::view_or_value.
Declares mongocxx::v_noabi::options::index.
Provides mongocxx::v1::indexes.
#define MONGOCXX_DEPRECATED
Declares the associated entity as deprecated.
Definition export.hpp:25
#define MONGOCXX_ABI_NO_EXPORT
Excludes the associated entity from being part of the ABI.
Definition export.hpp:20
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
#define MONGOCXX_ABI_EXPORT
Exports the associated entity as part of the ABI.
Definition export.hpp:15
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
The top-level namespace within which all bsoncxx library entities are declared.
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::document::value.
Provides bsoncxx::v_noabi::document::view.
Provides std::optional-related polyfills for library API usage.
Declares mongocxx::v_noabi::collection.