MongoDB C++ Driver 4.2.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
58class indexes {
59 // This class implements `IndexView` ("Index View API"):
60 // - https://specifications.readthedocs.io/en/latest/index-management/index-management/
61
62 private:
63 class impl;
64 void* _impl;
65
66 public:
93 class options {
94 // This class implements `IndexOptions` ("Index View API"):
95 // - https://specifications.readthedocs.io/en/latest/index-management/index-management/
96
97 private:
98 class impl;
99 void* _impl;
100
101 public:
108
116
123 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options&& other) noexcept;
124
129
133 MONGOCXX_ABI_EXPORT_CDECL(options&) operator=(options const& other);
134
142
147
151 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) background() const;
152
157
161 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) collation() const;
162
167
171 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) default_language() const;
172
177
181 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::seconds>) expire_after() const;
182
187
191 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) hidden() const;
192
197
201 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) language_override()
202 const;
203
208
212 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::stdx::string_view>) name() const;
213
218
223 const;
224
229
233 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) sparse() const;
234
239
243 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) storage_engine() const;
244
249
253 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) text_index_version() const;
254
259
263 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::uint8_t>) twod_bits_precision() const;
264
269
273 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<double>) twod_location_max() const;
274
279
283 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<double>) twod_location_min() const;
284
289
293 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::uint8_t>) twod_sphere_version() const;
294
299
303 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bool>) unique() const;
304
309
313 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) version() const;
314
319
323 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) wildcard_projection() const;
324
329
333 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) weights() const;
334
338 /* explicit(false) */ MONGOCXX_ABI_EXPORT_CDECL() operator bsoncxx::v1::document::value() const;
339
340 class internal;
341 };
342
355 class model {
356 // This class implements `IndexModel` ("Index View API"):
357 // - https://specifications.readthedocs.io/en/latest/index-management/index-management/
358
359 private:
360 class impl;
361 void* _impl;
362
363 public:
370
378
385 MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model&& other) noexcept;
386
391
395 MONGOCXX_ABI_EXPORT_CDECL(model&) operator=(model const& other);
396
401 model(bsoncxx::v1::document::value keys, options const& opts)
402 : model{std::move(keys), bsoncxx::v1::document::value{opts}} {}
403
406
414
418 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) keys() const;
419
423 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::document::view) options() const;
424 };
425
436 // This class implements `CreateOneIndexOptions` ("Index View API"):
437 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
438
439 private:
440 class impl;
441 void* _impl;
442
443 public:
450
458
465
470
475
483
488
492 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
493
498
502 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) commit_quorum() const;
503
508
512 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
513
518
523
524 class internal;
525 };
526
537 // This class implements `CreateManyIndexesOptions` ("Index View API"):
538 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
539
540 private:
541 void* _impl; // create_index_options_impl
542
543 public:
550
558
565
570
575
583
588
592 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
593
598
602 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::document::view>) commit_quorum() const;
603
608
612 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
613
618
623
624 class internal;
625 };
626
636 // This class implements `DropOneIndexOptions` ("Index View API"):
637 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
638
639 private:
640 void* _impl; // drop_index_options_impl
641
642 public:
649
657
664
669
674
682
687
691 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
692
697
701 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
702
707
712
713 class internal;
714 };
715
725 // This class implements `DropAllIndexesOptions` ("Index View API"):
726 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
727
728 private:
729 void* _impl; // drop_index_options_impl
730
731 public:
738
746
753
758
763
771
776
780 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
781
786
790 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::chrono::milliseconds>) max_time() const;
791
796
801
802 class internal;
803 };
804
813 // This class implements `ListIndexesOptions` ("Index View API"):
814 // - https://specifications.readthedocs.io/en/latest/index-management/index-management
815
816 private:
817 class impl;
818 void* _impl;
819
820 public:
827
835
842
847
852
860
865
869 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<std::int32_t>) batch_size() const;
870
875
879 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v1::stdx::optional<bsoncxx::v1::types::view>) comment() const;
880
881 class internal;
882 };
883
890
898
905 MONGOCXX_ABI_EXPORT_CDECL(indexes&) operator=(indexes&& other) noexcept;
906
911
915 MONGOCXX_ABI_EXPORT_CDECL(indexes&) operator=(indexes const& other);
916
923
931
937 bsoncxx::v1::document::value index_opts = {},
938 create_one_options const& create_opts = {}) {
939 return this->create_one(model{std::move(keys), std::move(index_opts)}, create_opts);
940 }
941
946 v1::client_session const& session,
948 bsoncxx::v1::document::value index_opts = {},
949 create_one_options const& create_opts = {}) {
950 return this->create_one(session, model{std::move(keys), std::move(index_opts)}, create_opts);
951 }
952
967 model const& index,
968 create_one_options const& create_opts = {});
969
985 create_one(v1::client_session const& session, model const& index, create_one_options const& create_opts = {});
986
1000 std::vector<model> const& indexes,
1001 create_many_options const& create_opts = {});
1002
1018 v1::client_session const& session,
1019 std::vector<model> const& indexes,
1020 create_many_options const& create_opts = {});
1021
1027 bsoncxx::v1::document::value index_opts = {},
1028 drop_one_options const& drop_opts = {}) {
1029 return this->drop_one(model{std::move(keys), std::move(index_opts)}, drop_opts);
1030 }
1031
1036 client_session const& session,
1038 bsoncxx::v1::document::value index_opts = {},
1039 drop_one_options const& drop_opts = {}) {
1040 return this->drop_one(session, model{std::move(keys), std::move(index_opts)}, drop_opts);
1041 }
1042
1055 drop_one_options const& drop_opts = {});
1056
1070 v1::client_session const& session,
1071 bsoncxx::v1::stdx::string_view index,
1072 drop_one_options const& drop_opts = {});
1073
1084 MONGOCXX_ABI_EXPORT_CDECL(void) drop_one(model const& index, drop_one_options const& drop_opts = {});
1085
1097 drop_one(v1::client_session const& session, model const& index, drop_one_options const& drop_opts = {});
1098
1108
1118 MONGOCXX_ABI_EXPORT_CDECL(void) drop_all(v1::client_session const& session, drop_all_options const& drop_opts = {});
1119
1130
1136 static MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) error_category();
1137
1143 friend std::error_code make_error_code(errc v) {
1144 return {static_cast<int>(v), error_category()};
1145 }
1146
1147 class internal;
1148
1149 private:
1150 /* explicit(false) */ indexes(void* impl);
1151};
1152
1153} // namespace v1
1154} // namespace mongocxx
1155
1156namespace std {
1157
1158template <>
1159struct is_error_code_enum<mongocxx::v1::indexes::errc> : true_type {};
1160
1161} // namespace std
1162
1164
A BSON document.
Definition value.hpp:46
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:48
A MongoDB cursor.
Definition cursor.hpp:41
Options for mongocxx::v1::indexes::create_many.
Definition indexes.hpp:536
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:435
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:724
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:635
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:812
~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:355
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:1025
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:1035
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:935
errc
Errors codes which may be returned by mongocxx::v1::indexes.
Definition indexes.hpp:1125
@ invalid_name
"*" is not a permitted index name.
Definition indexes.hpp:1128
@ expired_after_i32
The "expiredAfterSeconds" field must be representable as an std::int32_t.
Definition indexes.hpp:1127
@ zero
Zero.
Definition indexes.hpp:1126
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:945
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:1143
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:42
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.