MongoDB C++ Driver 4.4.0
Loading...
Searching...
No Matches
indexes.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/v1/indexes-fwd.hpp> // IWYU pragma: export
18
19//
20
22
25
29
34
36
37#include <chrono>
38#include <cstdint>
39#include <string>
40#include <system_error>
41#include <type_traits>
42#include <utility>
43#include <vector>
44
45namespace mongocxx {
46namespace v1 {
47
56class indexes {
57 // This class implements `IndexView` ("Index View API"):
58 // - https://specifications.readthedocs.io/en/latest/index-management/index-management/
59
60 private:
61 class impl;
62 void* _impl;
63
64 public:
89 class options {
90 // This class implements `IndexOptions` ("Index View API"):
91 // - https://specifications.readthedocs.io/en/latest/index-management/index-management/
92
93 private:
94 class impl;
95 void* _impl;
96
97 public:
104
112
119 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept;
120
125
129 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other);
130
138
143
147 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) background() const;
148
153
157 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) collation() const;
158
163
167 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) default_language() const;
168
173
177 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::seconds>) expire_after() const;
178
183
187 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) hidden() const;
188
193
197 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) language_override()
198 const;
199
204
208 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) name() const;
209
214
219 const;
220
225
229 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) sparse() const;
230
235
239 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) storage_engine() const;
240
245
249 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) text_index_version() const;
250
255
259 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::uint8_t>) twod_bits_precision() const;
260
265
269 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<double>) twod_location_max() const;
270
275
279 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<double>) twod_location_min() const;
280
285
289 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::uint8_t>) twod_sphere_version() const;
290
295
299 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) unique() const;
300
305
309 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) version() const;
310
315
319 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) wildcard_projection() const;
320
325
329 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) weights() const;
330
334 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() operator bsoncxx::v1::document::value() const;
335
336 class internal;
337 };
338
349 class model {
350 // This class implements `IndexModel` ("Index View API"):
351 // - https://specifications.readthedocs.io/en/latest/index-management/index-management/
352
353 private:
354 class impl;
355 void* _impl;
356
357 public:
364
372
379 MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model&& other) noexcept;
380
385
389 MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model const& other);
390
395 model(bsoncxx::v1::document::value keys, options const& opts)
396 : model{std::move(keys), bsoncxx::v1::document::value{opts}} {}
397
400
408
412 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) keys() const;
413
417 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) options() const;
418 };
419
430 // This class implements `CreateOneIndexOptions` ("Index View API"):
431 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
432
433 private:
434 class impl;
435 void* _impl;
436
437 public:
444
452
459
464
469
477
482
486 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
487
492
496 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) commit_quorum() const;
497
502
506 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
507
512
517
518 class internal;
519 };
520
531 // This class implements `CreateManyIndexesOptions` ("Index View API"):
532 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
533
534 private:
535 void* _impl; // create_index_options_impl
536
537 public:
544
552
559
564
569
577
582
586 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
587
592
596 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) commit_quorum() const;
597
602
606 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
607
612
617
618 class internal;
619 };
620
630 // This class implements `DropOneIndexOptions` ("Index View API"):
631 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
632
633 private:
634 void* _impl; // drop_index_options_impl
635
636 public:
643
651
658
663
668
676
681
685 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
686
691
695 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
696
701
706
707 class internal;
708 };
709
719 // This class implements `DropAllIndexesOptions` ("Index View API"):
720 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
721
722 private:
723 void* _impl; // drop_index_options_impl
724
725 public:
732
740
747
752
757
765
770
774 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
775
780
784 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
785
790
795
796 class internal;
797 };
798
807 // This class implements `ListIndexesOptions` ("Index View API"):
808 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
809
810 private:
811 class impl;
812 void* _impl;
813
814 public:
821
829
836
841
846
854
859
863 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) batch_size() const;
864
869
873 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
874
875 class internal;
876 };
877
884
892
899 MONGOCXX_ABI_EXPORT_CDECL(indexes&) operator=(indexes&& other) noexcept;
900
905
909 MONGOCXX_ABI_EXPORT_CDECL(indexes&) operator=(indexes const& other);
910
917
925
931 bsoncxx::v1::document::value index_opts = {},
932 create_one_options const& create_opts = {}) {
933 return this->create_one(model{std::move(keys), std::move(index_opts)}, create_opts);
934 }
935
940 v1::client_session const& session,
942 bsoncxx::v1::document::value index_opts = {},
943 create_one_options const& create_opts = {}) {
944 return this->create_one(session, model{std::move(keys), std::move(index_opts)}, create_opts);
945 }
946
961 model const& index,
962 create_one_options const& create_opts = {});
963
979 create_one(v1::client_session const& session, model const& index, create_one_options const& create_opts = {});
980
994 std::vector<model> const& indexes,
995 create_many_options const& create_opts = {});
996
1012 v1::client_session const& session,
1013 std::vector<model> const& indexes,
1014 create_many_options const& create_opts = {});
1015
1021 bsoncxx::v1::document::value index_opts = {},
1022 drop_one_options const& drop_opts = {}) {
1023 return this->drop_one(model{std::move(keys), std::move(index_opts)}, drop_opts);
1024 }
1025
1030 client_session const& session,
1032 bsoncxx::v1::document::value index_opts = {},
1033 drop_one_options const& drop_opts = {}) {
1034 return this->drop_one(session, model{std::move(keys), std::move(index_opts)}, drop_opts);
1035 }
1036
1049 drop_one_options const& drop_opts = {});
1050
1064 v1::client_session const& session,
1065 bsoncxx::v1::stdx::string_view index,
1066 drop_one_options const& drop_opts = {});
1067
1078 MONGOCXX_ABI_EXPORT_CDECL(void) drop_one(model const& index, drop_one_options const& drop_opts = {});
1079
1091 drop_one(v1::client_session const& session, model const& index, drop_one_options const& drop_opts = {});
1092
1102
1112 MONGOCXX_ABI_EXPORT_CDECL(void) drop_all(v1::client_session const& session, drop_all_options const& drop_opts = {});
1113
1122
1126 static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
1127
1131 friend std::error_code make_error_code(errc v) {
1132 return {static_cast<int>(v), error_category()};
1133 }
1134
1135 class internal;
1136
1137 private:
1138 /* explicit(false) */ indexes(void* impl);
1139};
1140
1141} // namespace v1
1142} // namespace mongocxx
1143
1144namespace std {
1145
1146template <>
1147struct is_error_code_enum<mongocxx::v1::indexes::errc> : true_type {};
1148
1149} // namespace std
1150
1152
A BSON document.
Definition value.hpp:44
A polyfill for std::optional<T>.
Definition optional.hpp:799
A polyfill for std::string_view.
Definition string_view.hpp:412
A MongoDB client session.
Definition client_session.hpp:46
A MongoDB cursor.
Definition cursor.hpp:39
Options for mongocxx::v1::indexes::create_many.
Definition indexes.hpp:530
create_many_options(create_many_options &&other) noexcept
Move constructor.
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 & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
create_many_options & max_time(std::chrono::milliseconds v)
Set the "maxTimeMS" field.
Options for mongocxx::v1::indexes::create_one.
Definition indexes.hpp:429
create_one_options(create_one_options &&other) noexcept
Move constructor.
create_one_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
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.
Options for mongocxx::v1::indexes::drop_all.
Definition indexes.hpp:718
drop_all_options & max_time(std::chrono::milliseconds v)
Set the "maxTimeMS" field.
drop_all_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
drop_all_options(drop_all_options &&other) noexcept
Move constructor.
~drop_all_options()
Destroy this object.
drop_all_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
Options for mongocxx::v1::indexes::drop_one.
Definition indexes.hpp:629
drop_one_options & write_concern(v1::write_concern v)
Set the "writeConcern" field.
drop_one_options(drop_one_options &&other) noexcept
Move constructor.
drop_one_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
drop_one_options & max_time(std::chrono::milliseconds v)
Set the "maxTimeMS" field.
~drop_one_options()
Destroy this object.
Options for mongocxx::v1::indexes::list.
Definition indexes.hpp:806
~list_options()
Destroy this object.
list_options & batch_size(std::int32_t v)
Set the "batchSize" field.
list_options(list_options &&other) noexcept
Move constructor.
list_options & comment(bsoncxx::v1::types::value v)
Set the "comment" field.
A description of a MongoDB index.
Definition indexes.hpp:349
bsoncxx::v1::document::view options() const
Return the current "options" field.
model(model &&other) noexcept
Move constructor.
bsoncxx::v1::document::view keys() const
Return the current "keys" field.
~model()
Destroy this object.
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 & wildcard_projection(bsoncxx::v1::document::value v)
Set the "wildcardProjection" field.
options & background(bool v)
Set the "background" field.
options & partial_filter_expression(bsoncxx::v1::document::value v)
Set the "partialFilterExpression" field.
options(options &&other) noexcept
Move constructor.
~options()
Destroy this object.
options & language_override(std::string v)
Set the "language_override" field.
operator bsoncxx::v1::document::value() const
Return these index management options as a document.
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 & text_index_version(std::int32_t v)
Set the "textIndexVersion" 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.
v1::cursor list(v1::client_session const &session, list_options const &list_opts={})
Return all indexes in the associated collection.
void drop_one(bsoncxx::v1::document::value keys, bsoncxx::v1::document::value index_opts={}, drop_one_options const &drop_opts={})
Equivalent to this->drop_one(mongocxx::v1::indexes::model(keys, index_opts), drop_opts).
Definition indexes.hpp:1019
void drop_one(client_session const &session, bsoncxx::v1::document::value keys, bsoncxx::v1::document::value index_opts={}, drop_one_options const &drop_opts={})
Equivalent to this->drop_one(session, mongocxx::v1::indexes::model(keys, index_opts),...
Definition indexes.hpp:1029
static std::error_category const & error_category()
The error category for mongocxx::v1::instance::errc.
bsoncxx::v1::stdx::optional< std::string > create_one(model const &index, create_one_options const &create_opts={})
Create a single index in the associated collection.
bsoncxx::v1::stdx::optional< std::string > create_one(bsoncxx::v1::document::value keys, bsoncxx::v1::document::value index_opts={}, create_one_options const &create_opts={})
Equivalent to this->create_one(model(keys, index_opts), create_opts).
Definition indexes.hpp:929
errc
Errors codes which may be returned by mongocxx::v1::indexes.
Definition indexes.hpp:1117
@ invalid_name
"*" is not a permitted index name.
Definition indexes.hpp:1120
@ expired_after_i32
The "expiredAfterSeconds" field must be representable as an std::int32_t.
Definition indexes.hpp:1119
@ zero
Zero.
Definition indexes.hpp:1118
bsoncxx::v1::stdx::optional< std::string > create_one(v1::client_session const &session, bsoncxx::v1::document::value keys, bsoncxx::v1::document::value index_opts={}, create_one_options const &create_opts={})
Equivalent to this->create_one(session, model(keys, index_opts), create_opts).
Definition indexes.hpp:939
v1::cursor list(list_options const &list_opts={})
Return all indexes in the associated collection.
bsoncxx::v1::document::value create_many(std::vector< model > const &indexes, create_many_options const &create_opts={})
Create multiple indexes in the associated collection.
friend std::error_code make_error_code(errc v)
Support implicit conversion to std::error_code.
Definition indexes.hpp:1131
void drop_all(v1::client_session const &session, drop_all_options const &drop_opts={})
Drop all indexes in the associated collection.
void drop_one(model const &index, drop_one_options const &drop_opts={})
Drop a single index in the associated collection.
void drop_all(drop_all_options const &drop_opts={})
Drop all indexes in the associated collection.
indexes(indexes &&other) noexcept
Move constructor.
void drop_one(bsoncxx::v1::stdx::string_view index, drop_one_options const &drop_opts={})
Drop a single index in the associated collection.
Declares mongocxx::v1::indexes.
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard postlude header.
The mongocxx v1 macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
Declares entities representing bulk write operations.
Declares entities whose ABI stability is guaranteed for documented symbols.
@ mongocxx
From the mongocxx library.
Definition exception.hpp:40
The top-level namespace within which all mongocxx library entities are declared.
Declares mongocxx::v1::client_session.
Declares mongocxx::v1::cursor.
Provides bsoncxx::v1::document::value.
Provides bsoncxx::v1::document::view.
Provides std::optional-related polyfills for library API usage.
Provides std::string_view-related polyfills for library API usage.
Declares bsoncxx::v1::types::value.
Declares non-owning, read-only entities representing a BSON type value.
Declares mongocxx::v1::write_concern.