MongoDB C++ Driver  mongocxx-3.1.0
Public Types | Public Member Functions | List of all members
mongocxx::validation_criteria Class Reference

Class representing criteria for document validation, to be applied to a collection. More...

#include <validation_criteria.hpp>

Public Types

enum  validation_level
 A class to represent the different validation level options. More...
 
enum  validation_action
 A class to represent the different validation action options. More...
 

Public Member Functions

validation_criteriarule (bsoncxx::document::view_or_value rule)
 Sets a validation rule for this validation object. More...
 
const stdx::optional< bsoncxx::document::view_or_value > & rule () const
 Gets the validation rule for this validation object. More...
 
validation_criterialevel (validation_level level)
 Sets a validation level. More...
 
const stdx::optional< validation_level > & level () const
 Gets the validation level. More...
 
validation_criteriaaction (validation_action action)
 Sets a validation action to run when documents failing validation are inserted or modified. More...
 
const stdx::optional< validation_action > & action () const
 Gets the validation action to run when documents failing validation are inserted or modified. More...
 
bsoncxx::document::value to_document () const
 Returns a bson document representing this set of validation criteria. More...
 
 operator bsoncxx::document::value () const
 

Detailed Description

Class representing criteria for document validation, to be applied to a collection.

See also
https://docs.mongodb.com/master/core/document-validation/

Member Enumeration Documentation

A class to represent the different validation action options.

  • k_error: Reject any insertion or update that violates the validation criteria.
  • k_warn: Log any violations of the validation criteria, but allow the insertion or update to proceed.

A class to represent the different validation level options.

  • k_off: Disable validation entirely.
  • k_moderate: Apply validation rules to inserts, and apply validation rules to updates only if the document to be updated already fulfills the validation criteria.
  • k_strict: Apply validation rules to all inserts and updates.

Member Function Documentation

validation_criteria& mongocxx::validation_criteria::action ( validation_action  action)

Sets a validation action to run when documents failing validation are inserted or modified.

Parameters
actionAn enumerated validation action.
const stdx::optional<validation_action>& mongocxx::validation_criteria::action ( ) const

Gets the validation action to run when documents failing validation are inserted or modified.

Returns
The enumerated validation action.
validation_criteria& mongocxx::validation_criteria::level ( validation_level  level)

Sets a validation level.

Parameters
levelAn enumerated validation level.
const stdx::optional<validation_level>& mongocxx::validation_criteria::level ( ) const

Gets the validation level.

Returns
The enumerated validation level.
mongocxx::validation_criteria::operator bsoncxx::document::value ( ) const
Deprecated:
This method is deprecated. To determine which options are set on this object, use the provided accessors instead.
validation_criteria& mongocxx::validation_criteria::rule ( bsoncxx::document::view_or_value  rule)

Sets a validation rule for this validation object.

Parameters
ruleDocument representing a validation rule.
const stdx::optional<bsoncxx::document::view_or_value>& mongocxx::validation_criteria::rule ( ) const

Gets the validation rule for this validation object.

Returns
Document representing a validation rule.
bsoncxx::document::value mongocxx::validation_criteria::to_document ( ) const

Returns a bson document representing this set of validation criteria.

Deprecated:
This method is deprecated. To determine which options are set on this object, use the provided accessors instead.
Returns
Validation criteria, as a document.

The documentation for this class was generated from the following file: