MongoDB C++ Driver  mongocxx-3.9.0
•All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
index.hpp
1 // Copyright 2015 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 <chrono>
18 #include <memory>
19 
20 #include <bsoncxx/document/value.hpp>
21 #include <bsoncxx/document/view.hpp>
22 #include <bsoncxx/document/view_or_value.hpp>
23 #include <bsoncxx/stdx/optional.hpp>
24 #include <bsoncxx/string/view_or_value.hpp>
25 #include <mongocxx/stdx.hpp>
26 
27 #include <mongocxx/config/prelude.hpp>
28 
29 namespace mongocxx {
30 inline namespace v_noabi {
31 class collection;
32 
33 namespace options {
34 
40 class MONGOCXX_API index {
41  public:
45  class MONGOCXX_API base_storage_options {
46  public:
47  virtual ~base_storage_options();
48 
49  private:
50  friend class options::index;
51  MONGOCXX_PRIVATE virtual int type() const = 0;
52  };
53 
57  class MONGOCXX_API wiredtiger_storage_options final : public base_storage_options {
58  public:
59  ~wiredtiger_storage_options() override;
60 
67  void config_string(bsoncxx::string::view_or_value config_string);
68 
74  const stdx::optional<bsoncxx::string::view_or_value>& config_string() const;
75 
76  private:
77  friend collection;
78  MONGOCXX_PRIVATE int type() const override;
79  stdx::optional<bsoncxx::string::view_or_value> _config_string;
80  };
81 
82  index();
83 
97  index& background(bool background);
98 
104  const stdx::optional<bool>& background() const;
105 
119  index& unique(bool unique);
120 
126  const stdx::optional<bool>& unique() const;
127 
141  index& hidden(bool hidden);
142 
148  const stdx::optional<bool>& hidden() const;
149 
160  index& name(bsoncxx::string::view_or_value name);
161 
167  const stdx::optional<bsoncxx::string::view_or_value>& name() const;
168 
182  index& collation(bsoncxx::document::view collation);
183 
193  const stdx::optional<bsoncxx::document::view>& collation() const;
194 
208  index& sparse(bool sparse);
209 
215  const stdx::optional<bool>& sparse() const;
216 
228  index& storage_options(std::unique_ptr<base_storage_options> storage_options);
229 
237  index& storage_options(std::unique_ptr<wiredtiger_storage_options> storage_options);
238 
252  index& expire_after(std::chrono::seconds seconds);
253 
259  const stdx::optional<std::chrono::seconds>& expire_after() const;
260 
271  index& version(std::int32_t v);
272 
278  const stdx::optional<std::int32_t>& version() const;
279 
291  index& weights(bsoncxx::document::view weights);
292 
298  const stdx::optional<bsoncxx::document::view>& weights() const;
299 
311  index& default_language(bsoncxx::string::view_or_value default_language);
312 
318  const stdx::optional<bsoncxx::string::view_or_value>& default_language() const;
319 
331  index& language_override(bsoncxx::string::view_or_value language_override);
332 
338  const stdx::optional<bsoncxx::string::view_or_value>& language_override() const;
339 
350  index& partial_filter_expression(bsoncxx::document::view partial_filter_expression);
351 
357  const stdx::optional<bsoncxx::document::view>& partial_filter_expression() const;
358 
369  index& twod_sphere_version(std::uint8_t twod_sphere_version);
370 
376  const stdx::optional<std::uint8_t>& twod_sphere_version() const;
377 
388  index& twod_bits_precision(std::uint8_t twod_bits_precision);
389 
395  const stdx::optional<std::uint8_t>& twod_bits_precision() const;
396 
407  index& twod_location_min(double twod_location_min);
408 
414  const stdx::optional<double>& twod_location_min() const;
415 
426  index& twod_location_max(double twod_location_max);
427 
433  const stdx::optional<double>& twod_location_max() const;
434 
452  MONGOCXX_DEPRECATED index& haystack_bucket_size(double haystack_bucket_size);
453  index& haystack_bucket_size_deprecated(double haystack_bucket_size);
454 
463  MONGOCXX_DEPRECATED const stdx::optional<double>& haystack_bucket_size() const;
464  const stdx::optional<double>& haystack_bucket_size_deprecated() const;
465 
473  operator bsoncxx::document::view_or_value();
474 
475  private:
476  friend collection;
477 
478  stdx::optional<bool> _background;
479  stdx::optional<bool> _unique;
480  stdx::optional<bool> _hidden;
481  stdx::optional<bsoncxx::string::view_or_value> _name;
482  stdx::optional<bsoncxx::document::view> _collation;
483  stdx::optional<bool> _sparse;
484  std::unique_ptr<base_storage_options> _storage_options;
485  stdx::optional<std::chrono::seconds> _expire_after;
486  stdx::optional<std::int32_t> _version;
487  stdx::optional<bsoncxx::document::view> _weights;
488  stdx::optional<bsoncxx::string::view_or_value> _default_language;
489  stdx::optional<bsoncxx::string::view_or_value> _language_override;
490  stdx::optional<bsoncxx::document::view> _partial_filter_expression;
491  stdx::optional<std::uint8_t> _twod_sphere_version;
492  stdx::optional<std::uint8_t> _twod_bits_precision;
493  stdx::optional<double> _twod_location_min;
494  stdx::optional<double> _twod_location_max;
495  stdx::optional<double> _haystack_bucket_size;
496 
497  //
498  // Return the current storage_options setting.
499  //
500  const std::unique_ptr<base_storage_options>& storage_options() const;
501 };
502 
503 } // namespace options
504 } // namespace v_noabi
505 } // namespace mongocxx
506 
507 #include <mongocxx/config/postlude.hpp>
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:85
Base class representing the optional storage engine options for indexes.
Definition: index.hpp:45
Class representing the optional WiredTiger storage engine options for indexes.
Definition: index.hpp:57
const stdx::optional< bsoncxx::string::view_or_value > & config_string() const
The current config_string setting.
void config_string(bsoncxx::string::view_or_value config_string)
Set the WiredTiger configuration string.
Class representing the optional arguments to a MongoDB create index operation.
Definition: index.hpp:40
index & partial_filter_expression(bsoncxx::document::view partial_filter_expression)
Sets the document for the partial filter expression for partial indexes.
const stdx::optional< bsoncxx::string::view_or_value > & default_language() const
The current default_language setting.
const stdx::optional< bool > & hidden() const
The current hidden setting.
const stdx::optional< double > & haystack_bucket_size() const
The current haystack_bucket_size setting.
const stdx::optional< double > & twod_location_min() const
The current lower inclusive boundary for the longitude and latitude values.
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.
index & twod_location_min(double twod_location_min)
For 2d indexes, the lower inclusive boundary for the longitude and latitude values.
index & collation(bsoncxx::document::view collation)
Sets the collation for this index.
index & hidden(bool hidden)
Whether or not the index is hidden from the query planner.
const stdx::optional< std::chrono::seconds > & expire_after() const
The current expire_after setting.
index & language_override(bsoncxx::string::view_or_value language_override)
For text indexes, the name of the field, in the collection’s documents, that contains the override la...
const stdx::optional< std::uint8_t > & twod_sphere_version() const
The current twod_sphere_version setting.
index & background(bool background)
Whether or not to build the index in the background so that building the index does not block other d...
index & version(std::int32_t v)
Sets the index version.
index & unique(bool unique)
Whether or not to create a unique index so that the collection will not accept insertion of documents...
const stdx::optional< bsoncxx::document::view > & collation() const
Retrieves the current collation for this index.
index & twod_sphere_version(std::uint8_t twod_sphere_version)
For 2dsphere indexes, the 2dsphere index version number.
index & weights(bsoncxx::document::view weights)
For text indexes, sets the weight document.
const stdx::optional< bsoncxx::document::view > & partial_filter_expression() const
The current partial_filter_expression setting.
const stdx::optional< bsoncxx::document::view > & weights() const
The current weights setting.
index & storage_options(std::unique_ptr< base_storage_options > storage_options)
Optionally used only in MongoDB 3.0.0 and higher.
index & haystack_bucket_size(double haystack_bucket_size)
For geoHaystack indexes, specify the number of units within which to group the location values; i....
index & storage_options(std::unique_ptr< wiredtiger_storage_options > storage_options)
Optionally used only in MongoDB 3.0.0 and higher.
const stdx::optional< double > & twod_location_max() const
The current upper inclusive boundary for the longitude and latitude values.
const stdx::optional< bool > & unique() const
The current unique setting.
index & sparse(bool sparse)
Whether or not to create a sparse index.
const stdx::optional< std::int32_t > & version() const
The current index version.
const stdx::optional< std::uint8_t > & twod_bits_precision() const
The current precision of the stored geohash value of the location data.
index & twod_location_max(double twod_location_max)
For 2d indexes, the upper inclusive boundary for the longitude and latitude values.
const stdx::optional< bool > & sparse() const
The current sparse setting.
const stdx::optional< bsoncxx::string::view_or_value > & language_override() const
The current name of the field that contains the override language for text indexes.
const stdx::optional< bsoncxx::string::view_or_value > & name() const
The current name setting.
index & default_language(bsoncxx::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...
index & twod_bits_precision(std::uint8_t twod_bits_precision)
For 2d indexes, the precision of the stored geohash value of the location data.
index & name(bsoncxx::string::view_or_value name)
The name of the index.
const stdx::optional< bool > & background() const
The current background setting.
The top-level namespace for mongocxx library entities.
Definition: bulk_write.hpp:24