#include <userver/formats/bson/document.hpp>
BSON document.
Definition at line 14 of file document.hpp.
Public Types | |
enum class | DuplicateFieldsPolicy { kForbid , kUseFirst , kUseLast } |
Selectors for duplicate fields parsing behavior. More... | |
using | const_iterator = Iterator<const Value, common::IteratorDirection::kForward> |
using | const_reverse_iterator = Iterator<const Value, common::IteratorDirection::kReverse> |
using | Exception = formats::bson::BsonException |
using | ParseException = formats::bson::ParseException |
using | ExceptionWithPath = formats::bson::ExceptionWithPath |
using | Builder = ValueBuilder |
Public Member Functions | |
Document () | |
Constructs an empty document Equivalent to MakeDoc() | |
Document (const Value &value) | |
Unwraps document from Value. | |
Value | operator[] (const std::string &name) const |
Retrieves document field by name. | |
Value | operator[] (uint32_t index) const |
Retrieves array element by index. | |
bool | HasMember (const std::string &name) const |
Checks whether the document has a field. | |
const_iterator | begin () const |
Returns an iterator to the first array element/document field. | |
const_iterator | end () const |
Returns an iterator following the last array element/document field. | |
const_reverse_iterator | rbegin () const |
Returns a reversed iterator to the last array element. | |
const_reverse_iterator | rend () const |
Returns a reversed iterator following the first array element. | |
bool | IsEmpty () const |
Returns whether the document/array is empty. | |
uint32_t | GetSize () const |
Returns the number of elements in a document/array. | |
std::string | GetPath () const |
Returns value path in a document. | |
bool | operator== (const Value &) const |
bool | operator!= (const Value &) const |
bool | IsMissing () const |
Checks whether the selected element exists. | |
template<typename T> | |
auto | As () const |
template<typename T, typename First, typename... Rest> | |
auto | As (First &&default_arg, Rest &&... more_default_args) const |
template<typename T> | |
auto | As (DefaultConstructed) const |
Returns value of *this converted to T or T() if this->IsMissing(). | |
template<typename T> | |
T | ConvertTo () const |
Extracts the specified type with relaxed type checks. For example, true may be converted to 1.0. | |
template<typename T, typename First, typename... Rest> | |
T | ConvertTo (First &&default_arg, Rest &&... more_default_args) const |
void | SetDuplicateFieldsPolicy (DuplicateFieldsPolicy) |
Changes parsing behavior when duplicate fields are encountered. Should not be used normally. | |
void | CheckNotMissing () const |
Throws a MemberMissingException if the selected element does not exist. | |
void | CheckArrayOrNull () const |
Throws a TypeMismatchException if the selected element is not an array or null. | |
void | CheckDocumentOrNull () const |
Throws a TypeMismatchException if the selected element is not a document or null. | |
Type checking | |
bool | IsArray () const |
bool | IsDocument () const |
bool | IsNull () const |
bool | IsBool () const |
bool | IsInt32 () const |
bool | IsInt64 () const |
bool | IsDouble () const |
bool | IsString () const |
bool | IsDateTime () const |
bool | IsOid () const |
bool | IsBinary () const |
bool | IsDecimal128 () const |
bool | IsMinKey () const |
bool | IsMaxKey () const |
bool | IsTimestamp () const |
bool | IsObject () const |
Protected Member Functions | |
const impl::BsonHolder & | GetBson () const |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
inherited |
|
stronginherited |
Selectors for duplicate fields parsing behavior.
formats::bson::Document::Document | ( | const Value & | value | ) |
Unwraps document from Value.
TypeMismatchException | if value is not a document |
|
inlineinherited |
Extracts the specified type with strict type checks
|
inlineinherited |
Returns value of *this converted to T or T() if this->IsMissing().
Anything | derived from std::exception. |
value.As<T>({})
|
inlineinherited |
|
inherited |
Returns an iterator to the first array element/document field.
TypeMismatchException | if value is not a document, array or null |
To iterate over Value
as object use formats::common::Items.
|
inlineinherited |
|
inlineinherited |
|
inherited |
Returns an iterator following the last array element/document field.
TypeMismatchException | if value is not a document, array or null |
|
inherited |
Returns the number of elements in a document/array.
TypeMismatchException | if value is not a document, array or null |
null
.
|
inherited |
Checks whether the document has a field.
name | field name |
TypeMismatchExcepiton | if value is not a document or null |
|
inherited |
Returns whether the document/array is empty.
TypeMismatchException | if value is not a document, array or null |
true
for null
.
|
inherited |
Checks whether the selected element exists.
|
inlineinherited |
|
inherited |
Retrieves document field by name.
name | field name |
TypeMismatchException | if value is not a missing value, a document, or null |
|
inherited |
Retrieves array element by index.
index | element index |
TypeMismatchException | if value is not an array or null |
OutOfBoundsException | if index is invalid for the array |
|
inherited |
Returns a reversed iterator to the last array element.
TypeMismatchException | if value is not an array or null |
|
inherited |
Returns a reversed iterator following the first array element.
TypeMismatchException | if value is not an array or null |
|
inherited |
Changes parsing behavior when duplicate fields are encountered. Should not be used normally.
Should be called before the first field access. Only affects documents. Default policy is to throw an exception when duplicate fields are encountered.