MongoDB C++ Driver  mongocxx-3.6.2
•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/view.hpp>
21 #include <bsoncxx/stdx/optional.hpp>
22 #include <bsoncxx/string/view_or_value.hpp>
23 #include <mongocxx/stdx.hpp>
24 
25 #include <bsoncxx/document/value.hpp>
26 #include <bsoncxx/document/view_or_value.hpp>
27 #include <mongocxx/config/prelude.hpp>
28 
29 namespace mongocxx {
30 MONGOCXX_INLINE_NAMESPACE_BEGIN
31 
32 class collection;
33 
34 namespace options {
35 
41 class MONGOCXX_API index {
42  public:
46  class MONGOCXX_API base_storage_options {
47  public:
48  virtual ~base_storage_options();
49 
50  private:
51  friend class options::index;
52  MONGOCXX_PRIVATE virtual int type() const = 0;
53  };
54 
58  class MONGOCXX_API wiredtiger_storage_options final : public base_storage_options {
59  public:
60  ~wiredtiger_storage_options() override;
61 
69 
75  const stdx::optional<bsoncxx::string::view_or_value>& config_string() const;
76 
77  private:
78  friend collection;
79  MONGOCXX_PRIVATE int type() const override;
80  stdx::optional<bsoncxx::string::view_or_value> _config_string;
81  };
82 
83  index();
84 
98  index& background(bool background);
99 
105  const stdx::optional<bool>& background() const;
106 
120  index& unique(bool unique);
121 
127  const stdx::optional<bool>& unique() const;
128 
142  index& hidden(bool hidden);
143 
149  const stdx::optional<bool>& hidden() const;
150 
162 
168  const stdx::optional<bsoncxx::string::view_or_value>& name() const;
169 
184 
194  const stdx::optional<bsoncxx::document::view>& collation() const;
195 
209  index& sparse(bool sparse);
210 
216  const stdx::optional<bool>& sparse() const;
217 
229  index& storage_options(std::unique_ptr<base_storage_options> storage_options);
230 
238  index& storage_options(std::unique_ptr<wiredtiger_storage_options> storage_options);
239 
253  index& expire_after(std::chrono::seconds seconds);
254 
260  const stdx::optional<std::chrono::seconds>& expire_after() const;
261 
272  index& version(std::int32_t v);
273 
279  const stdx::optional<std::int32_t>& version() const;
280 
293 
299  const stdx::optional<bsoncxx::document::view>& weights() const;
300 
313 
319  const stdx::optional<bsoncxx::string::view_or_value>& default_language() const;
320 
333 
339  const stdx::optional<bsoncxx::string::view_or_value>& language_override() const;
340 
352 
358  const stdx::optional<bsoncxx::document::view>& partial_filter_expression() const;
359 
370  index& twod_sphere_version(std::uint8_t twod_sphere_version);
371 
377  const stdx::optional<std::uint8_t>& twod_sphere_version() const;
378 
389  index& twod_bits_precision(std::uint8_t twod_bits_precision);
390 
396  const stdx::optional<std::uint8_t>& twod_bits_precision() const;
397 
408  index& twod_location_min(double twod_location_min);
409 
415  const stdx::optional<double>& twod_location_min() const;
416 
427  index& twod_location_max(double twod_location_max);
428 
434  const stdx::optional<double>& twod_location_max() const;
435 
453  MONGOCXX_DEPRECATED index& haystack_bucket_size(double haystack_bucket_size);
454  index& haystack_bucket_size_deprecated(double haystack_bucket_size);
455 
464  MONGOCXX_DEPRECATED const stdx::optional<double>& haystack_bucket_size() const;
465  const stdx::optional<double>& haystack_bucket_size_deprecated() const;
466 
475 
476  private:
477  friend collection;
478 
479  stdx::optional<bool> _background;
480  stdx::optional<bool> _unique;
481  stdx::optional<bool> _hidden;
482  stdx::optional<bsoncxx::string::view_or_value> _name;
483  stdx::optional<bsoncxx::document::view> _collation;
484  stdx::optional<bool> _sparse;
485  std::unique_ptr<base_storage_options> _storage_options;
486  stdx::optional<std::chrono::seconds> _expire_after;
487  stdx::optional<std::int32_t> _version;
488  stdx::optional<bsoncxx::document::view> _weights;
489  stdx::optional<bsoncxx::string::view_or_value> _default_language;
490  stdx::optional<bsoncxx::string::view_or_value> _language_override;
491  stdx::optional<bsoncxx::document::view> _partial_filter_expression;
492  stdx::optional<std::uint8_t> _twod_sphere_version;
493  stdx::optional<std::uint8_t> _twod_bits_precision;
494  stdx::optional<double> _twod_location_min;
495  stdx::optional<double> _twod_location_max;
496  stdx::optional<double> _haystack_bucket_size;
497 
498  //
499  // Return the current storage_options setting.
500  //
501  const std::unique_ptr<base_storage_options>& storage_options() const;
502 };
503 
504 } // namespace options
505 MONGOCXX_INLINE_NAMESPACE_END
506 } // namespace mongocxx
507 
508 #include <mongocxx/config/postlude.hpp>
mongocxx::options::index::collation
const stdx::optional< bsoncxx::document::view > & collation() const
Retrieves the current collation for this index.
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
mongocxx::options::index::sparse
const stdx::optional< bool > & sparse() const
The current sparse setting.
mongocxx::options::index::language_override
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.
bsoncxx::view_or_value< document::view, document::value >
mongocxx::options::index::version
index & version(std::int32_t v)
Sets the index version.
mongocxx::options::index::background
const stdx::optional< bool > & background() const
The current background setting.
mongocxx::options::index
Class representing the optional arguments to a MongoDB create index operation.
Definition: index.hpp:41
mongocxx::options::index::background
index & background(bool background)
Whether or not to build the index in the background so that building the index does not block other d...
mongocxx::options::index::unique
index & unique(bool unique)
Whether or not to create a unique index so that the collection will not accept insertion of documents...
mongocxx::options::index::haystack_bucket_size
MONGOCXX_DEPRECATED index & haystack_bucket_size(double haystack_bucket_size)
For geoHaystack indexes, specify the number of units within which to group the location values; i....
mongocxx::options::index::wiredtiger_storage_options::config_string
void config_string(bsoncxx::string::view_or_value config_string)
Set the WiredTiger configuration string.
mongocxx::options::index::partial_filter_expression
index & partial_filter_expression(bsoncxx::document::view partial_filter_expression)
Sets the document for the partial filter expression for partial indexes.
mongocxx::options::index::twod_bits_precision
index & twod_bits_precision(std::uint8_t twod_bits_precision)
For 2d indexes, the precision of the stored geohash value of the location data.
mongocxx::options::index::storage_options
index & storage_options(std::unique_ptr< base_storage_options > storage_options)
Optionally used only in MongoDB 3.0.0 and higher.
mongocxx::options::index::twod_sphere_version
index & twod_sphere_version(std::uint8_t twod_sphere_version)
For 2dsphere indexes, the 2dsphere index version number.
mongocxx::options::index::wiredtiger_storage_options
Class representing the optional WiredTiger storage engine options for indexes.
Definition: index.hpp:58
mongocxx::options::index::haystack_bucket_size
MONGOCXX_DEPRECATED const stdx::optional< double > & haystack_bucket_size() const
The current haystack_bucket_size setting.
mongocxx::options::index::default_language
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...
mongocxx::options::index::sparse
index & sparse(bool sparse)
Whether or not to create a sparse index.
bsoncxx::string::view_or_value
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
mongocxx::options::index::name
const stdx::optional< bsoncxx::string::view_or_value > & name() const
The current name setting.
mongocxx::options::index::hidden
index & hidden(bool hidden)
Whether or not the index is hidden from the query planner.
mongocxx::options::index::twod_location_min
index & twod_location_min(double twod_location_min)
For 2d indexes, the lower inclusive boundary for the longitude and latitude values.
mongocxx::options::index::unique
const stdx::optional< bool > & unique() const
The current unique setting.
mongocxx::options::index::collation
index & collation(bsoncxx::document::view collation)
Sets the collation for this index.
mongocxx::options::index::expire_after
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.
mongocxx::options::index::twod_sphere_version
const stdx::optional< std::uint8_t > & twod_sphere_version() const
The current twod_sphere_version setting.
mongocxx::options::index::storage_options
index & storage_options(std::unique_ptr< wiredtiger_storage_options > storage_options)
Optionally used only in MongoDB 3.0.0 and higher.
mongocxx::options::index::name
index & name(bsoncxx::string::view_or_value name)
The name of the index.
mongocxx::options::index::twod_location_max
const stdx::optional< double > & twod_location_max() const
The current upper inclusive boundary for the longitude and latitude values.
mongocxx::options::index::version
const stdx::optional< std::int32_t > & version() const
The current index version.
mongocxx::options::index::base_storage_options
Base class representing the optional storage engine options for indexes.
Definition: index.hpp:46
mongocxx::options::index::weights
const stdx::optional< bsoncxx::document::view > & weights() const
The current weights setting.
mongocxx::options::index::partial_filter_expression
const stdx::optional< bsoncxx::document::view > & partial_filter_expression() const
The current partial_filter_expression setting.
mongocxx::options::index::twod_bits_precision
const stdx::optional< std::uint8_t > & twod_bits_precision() const
The current precision of the stored geohash value of the location data.
mongocxx::options::index::expire_after
const stdx::optional< std::chrono::seconds > & expire_after() const
The current expire_after setting.
mongocxx::options::index::default_language
const stdx::optional< bsoncxx::string::view_or_value > & default_language() const
The current default_language setting.
mongocxx::options::index::hidden
const stdx::optional< bool > & hidden() const
The current hidden setting.
mongocxx::options::index::wiredtiger_storage_options::config_string
const stdx::optional< bsoncxx::string::view_or_value > & config_string() const
The current config_string setting.
mongocxx::options::index::language_override
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...
mongocxx::options::index::twod_location_min
const stdx::optional< double > & twod_location_min() const
The current lower inclusive boundary for the longitude and latitude values.
mongocxx::collection
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:81
bsoncxx::document::view
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
mongocxx::options::index::weights
index & weights(bsoncxx::document::view weights)
For text indexes, sets the weight document.
mongocxx::options::index::twod_location_max
index & twod_location_max(double twod_location_max)
For 2d indexes, the upper inclusive boundary for the longitude and latitude values.