MongoDB C++ Driver  mongocxx-3.1.1
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 <mongocxx/config/prelude.hpp>
26 
27 namespace mongocxx {
28 MONGOCXX_INLINE_NAMESPACE_BEGIN
29 
30 class collection;
31 
32 namespace options {
33 
39 class MONGOCXX_API index {
40  public:
44  class MONGOCXX_API base_storage_options {
45  public:
46  virtual ~base_storage_options();
47 
48  private:
49  friend collection;
50  MONGOCXX_PRIVATE virtual int type() const = 0;
51  };
52 
56  class MONGOCXX_API wiredtiger_storage_options final : public base_storage_options {
57  public:
58  ~wiredtiger_storage_options() override;
59 
66  void config_string(bsoncxx::string::view_or_value config_string);
67 
73  const stdx::optional<bsoncxx::string::view_or_value>& config_string() const;
74 
75  private:
76  friend collection;
77  MONGOCXX_PRIVATE int type() const override;
78  stdx::optional<bsoncxx::string::view_or_value> _config_string;
79  };
80 
81  index();
82 
92  index& background(bool background);
93 
99  const stdx::optional<bool>& background() const;
100 
110  index& unique(bool unique);
111 
117  const stdx::optional<bool>& unique() const;
118 
126 
132  const stdx::optional<bsoncxx::string::view_or_value>& name() const;
133 
143  index& collation(bsoncxx::document::view collation);
144 
154  const stdx::optional<bsoncxx::document::view>& collation() const;
155 
165  index& sparse(bool sparse);
166 
172  const stdx::optional<bool>& sparse() const;
173 
181  index& storage_options(std::unique_ptr<base_storage_options> storage_options);
182 
186  index& storage_options(std::unique_ptr<wiredtiger_storage_options> storage_options);
187 
197  index& expire_after(std::chrono::seconds seconds);
198 
204  const stdx::optional<std::chrono::seconds>& expire_after() const;
205 
212  index& version(std::int32_t v);
213 
219  const stdx::optional<std::int32_t>& version() const;
220 
228  index& weights(bsoncxx::document::view weights);
229 
235  const stdx::optional<bsoncxx::document::view>& weights() const;
236 
244  index& default_language(bsoncxx::string::view_or_value default_language);
245 
251  const stdx::optional<bsoncxx::string::view_or_value>& default_language() const;
252 
260  index& language_override(bsoncxx::string::view_or_value language_override);
261 
267  const stdx::optional<bsoncxx::string::view_or_value>& language_override() const;
268 
275  index& partial_filter_expression(bsoncxx::document::view partial_filter_expression);
276 
282  const stdx::optional<bsoncxx::document::view>& partial_filter_expression() const;
283 
290  index& twod_sphere_version(std::uint8_t twod_sphere_version);
291 
297  const stdx::optional<std::uint8_t>& twod_sphere_version() const;
298 
305  index& twod_bits_precision(std::uint8_t twod_bits_precision);
306 
312  const stdx::optional<std::uint8_t>& twod_bits_precision() const;
313 
320  index& twod_location_min(double twod_location_min);
321 
327  const stdx::optional<double>& twod_location_min() const;
328 
335  index& twod_location_max(double twod_location_max);
336 
342  const stdx::optional<double>& twod_location_max() const;
343 
354  index& haystack_bucket_size(double haystack_bucket_size);
355 
361  const stdx::optional<double>& haystack_bucket_size() const;
362 
363  private:
364  friend collection;
365 
366  stdx::optional<bool> _background;
367  stdx::optional<bool> _unique;
368  stdx::optional<bsoncxx::string::view_or_value> _name;
369  stdx::optional<bsoncxx::document::view> _collation;
370  stdx::optional<bool> _sparse;
371  std::unique_ptr<base_storage_options> _storage_options;
372  stdx::optional<std::chrono::seconds> _expire_after;
373  stdx::optional<std::int32_t> _version;
374  stdx::optional<bsoncxx::document::view> _weights;
375  stdx::optional<bsoncxx::string::view_or_value> _default_language;
376  stdx::optional<bsoncxx::string::view_or_value> _language_override;
377  stdx::optional<bsoncxx::document::view> _partial_filter_expression;
378  stdx::optional<std::uint8_t> _twod_sphere_version;
379  stdx::optional<std::uint8_t> _twod_bits_precision;
380  stdx::optional<double> _twod_location_min;
381  stdx::optional<double> _twod_location_max;
382  stdx::optional<double> _haystack_bucket_size;
383 
384  //
385  // Return the current storage_options setting.
386  //
387  const std::unique_ptr<base_storage_options>& storage_options() const;
388 };
389 
390 } // namespace options
391 MONGOCXX_INLINE_NAMESPACE_END
392 } // namespace mongocxx
393 
394 #include <mongocxx/config/postlude.hpp>
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:22
A read-only, non-owning view of a BSON document.
Definition: view.hpp:33
Base class representing the optional storage engine options for indexes.
Definition: index.hpp:44
Class representing a view-or-value variant type for strings.
Definition: view_or_value.hpp:36
Class representing the optional arguments to a MongoDB create index operation.
Definition: index.hpp:39
Class representing the optional WiredTiger storage engine options for indexes.
Definition: index.hpp:56
Class representing server side document groupings within a MongoDB database.
Definition: collection.hpp:74