MongoDB C++ Driver  mongocxx-3.10.2
update_one.hpp
1 // Copyright 2014 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/model/update_one-fwd.hpp>
18 
19 #include <bsoncxx/array/view_or_value.hpp>
20 #include <bsoncxx/document/view_or_value.hpp>
21 #include <bsoncxx/stdx/optional.hpp>
22 #include <mongocxx/hint.hpp>
23 #include <mongocxx/pipeline.hpp>
24 #include <mongocxx/stdx.hpp>
25 
26 #include <mongocxx/config/prelude.hpp>
27 
28 namespace mongocxx {
29 namespace v_noabi {
30 namespace model {
31 
35 class update_one {
36  //
37  // Utility class supporting the convenience of {} meaning an empty bsoncxx::v_noabi::document.
38  //
39  // Users may not use this class directly.
40  //
41  // In places where driver methods take this class as a parameter, passing {} will
42  // translate to a default-constructed bsoncxx::v_noabi::document::view_or_value,
43  // regardless of other overloads taking other default-constructible types
44  // for that parameter. This class avoids compiler ambiguity with such overloads.
45  //
46  // See update_one() for an example of such overloads.
47  //
48  class _empty_doc_tag {
49  _empty_doc_tag() = default;
50  };
51 
52  public:
65 
75 
85  std::initializer_list<_empty_doc_tag> update);
86 
90 
97 
104 
115 
125  const stdx::optional<bsoncxx::v_noabi::document::view_or_value>& collation() const;
126 
141 
147  const stdx::optional<mongocxx::v_noabi::hint>& hint() const;
148 
163 
169  const stdx::optional<bool>& upsert() const;
170 
180 
189  const stdx::optional<bsoncxx::v_noabi::array::view_or_value>& array_filters() const;
190 
191  private:
194 
195  stdx::optional<bsoncxx::v_noabi::document::view_or_value> _collation;
196  stdx::optional<bsoncxx::v_noabi::array::view_or_value> _array_filters;
197  stdx::optional<bool> _upsert;
198  stdx::optional<mongocxx::v_noabi::hint> _hint;
199 };
200 
201 } // namespace model
202 } // namespace v_noabi
203 } // namespace mongocxx
204 
205 #include <mongocxx/config/postlude.hpp>
Class representing a hint to be passed to a database operation.
Definition: hint.hpp:34
Class representing a MongoDB update operation that modifies a single document.
Definition: update_one.hpp:35
update_one & array_filters(bsoncxx::v_noabi::array::view_or_value array_filters)
Set array filters for this update operation.
const bsoncxx::v_noabi::document::view_or_value & filter() const
Gets the filter.
update_one & upsert(bool upsert)
Sets the upsert option.
const stdx::optional< bsoncxx::v_noabi::document::view_or_value > & collation() const
Gets the collation option for this update operation.
update_one & hint(mongocxx::v_noabi::hint index_hint)
Sets the index to use for this operation.
const stdx::optional< mongocxx::v_noabi::hint > & hint() const
Gets the current hint.
update_one(bsoncxx::v_noabi::document::view_or_value filter, std::initializer_list< _empty_doc_tag > update)
Constructs an update operation that will modify a single document matching the filter.
update_one(bsoncxx::v_noabi::document::view_or_value filter, bsoncxx::v_noabi::document::view_or_value update)
Constructs an update operation that will modify a single document matching the filter.
update_one & collation(bsoncxx::v_noabi::document::view_or_value collation)
Sets the collation for this update operation.
update_one(bsoncxx::v_noabi::document::view_or_value filter, const pipeline &update)
Constructs an update operation that will modify a single document matching the filter.
const stdx::optional< bool > & upsert() const
Gets the current value of the upsert option.
const bsoncxx::v_noabi::document::view_or_value & update() const
Gets the update document.
const stdx::optional< bsoncxx::v_noabi::array::view_or_value > & array_filters() const
Get array filters for this operation.
Class representing a MongoDB aggregation pipeline.
Definition: pipeline.hpp:39
The top-level namespace for mongocxx library entities.
Definition: bulk_write-fwd.hpp:19