MongoDB C++ Driver mongocxx-3.0.3
Loading...
Searching...
No Matches
validation_criteria.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 <bsoncxx/document/view_or_value.hpp>
18#include <bsoncxx/stdx/optional.hpp>
19#include <mongocxx/stdx.hpp>
20
21#include <mongocxx/config/prelude.hpp>
22
23namespace mongocxx {
24MONGOCXX_INLINE_NAMESPACE_BEGIN
25
31class MONGOCXX_API validation_criteria {
32 public:
40
44 enum class validation_level {
45 k_off,
46 k_moderate,
47 k_strict,
48 };
49
57
63 enum class validation_action {
64 k_error,
65 k_warn,
66 };
67
76
83
87 MONGOCXX_INLINE operator bsoncxx::document::value() const;
88
89 private:
90 stdx::optional<bsoncxx::document::view_or_value> _rule;
91 stdx::optional<validation_level> _level;
92 stdx::optional<validation_action> _action;
93};
94
95MONGOCXX_INLINE validation_criteria::operator bsoncxx::document::value() const {
96 return to_document();
97}
98
99MONGOCXX_INLINE_NAMESPACE_END
100} // namespace mongocxx
101
102#include <mongocxx/config/postlude.hpp>
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:33
Class representing criteria for document validation, to be applied to a collection.
Definition validation_criteria.hpp:31
bsoncxx::document::value to_document() const
Return a bson document representing this set of validation criteria.
void rule(bsoncxx::document::view_or_value rule)
Set a validation rule for this validation object.
void action(validation_action action)
Set a validation action to run when documents failing validation are inserted or modified.
void level(validation_level level)
Set a validation level.
validation_level
A class to represent the different validation level options.
Definition validation_criteria.hpp:44
validation_action
A class to represent the different validation action options.
Definition validation_criteria.hpp:63