Poco::MongoDB

class Document

File Information

Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/Document.h

Description

Represents a MongoDB (BSON) document.

Inheritance

Known Derived Classes: Cursor, Array

Member Summary

Member Functions: add, addElement, addNewDocument, clear, elementNames, empty, exists, get, getInteger, isType, read, size, toString, write

Types Aliases

Ptr

using Ptr = SharedPtr < Document >;

Vector

using Vector = std::vector < Document::Ptr >;

Constructors

Document

Document();

Creates an empty Document.

Destructor

~Document virtual

virtual ~Document();

Destroys the Document.

Member Functions

add inline

template < typename T > Document & add(
    const std::string & name,
    T value
);

Creates an element with the given name and value and adds it to the document.

The active document is returned to allow chaining of the add methods.

add inline

Document & add(
    const std::string & name,
    const char * value
);

Creates an element with the given name and value and adds it to the document.

The active document is returned to allow chaining of the add methods.

addElement inline

Document & addElement(
    Element::Ptr element
);

Add an element to the document.

The active document is returned to allow chaining of the add methods.

addNewDocument inline

Document & addNewDocument(
    const std::string & name
);

Create a new document and add it to this document. Unlike the other add methods, this method returns a reference to the new document.

clear inline

void clear();

Removes all elements from the document.

elementNames inline

void elementNames(
    std::vector < std::string > & keys
) const;

Puts all element names into std::vector.

empty inline

bool empty() const;

Returns true if the document doesn't contain any documents.

exists inline

bool exists(
    const std::string & name
);

Returns true if the document has an element with the given name.

get inline

template < typename T > T get(
    const std::string & name
) const;

Returns the element with the given name and tries to convert it to the template type. When the element is not found, a NotFoundException will be thrown. When the element can't be converted a BadCastException will be thrown.

get inline

template < typename T > T get(
    const std::string & name,
    const T & def
) const;

Returns the element with the given name and tries to convert it to the template type. When the element is not found, or has the wrong type, the def argument will be returned.

get

Element::Ptr get(
    const std::string & name
) const;

Returns the element with the given name. An empty element will be returned when the element is not found.

getInteger

Int64 getInteger(
    const std::string & name
) const;

Returns an integer. Useful when MongoDB returns Int32, Int64 or double for a number (count for example). This method will always return an Int64. When the element is not found, a Poco::NotFoundException will be thrown.

isType inline

template < typename T > bool isType(
    const std::string & name
) const;

Returns true when the type of the element equals the TypeId of ElementTrait.

read

void read(
    BinaryReader & reader
);

Reads a document from the reader

size inline

std::size_t size() const;

Returns the number of elements in the document.

toString virtual

virtual std::string toString(
    int indent = 0
) const;

Returns a String representation of the document.

write

void write(
    BinaryWriter & writer
);

Writes a document to the reader

Variables

_elements protected

ElementSet _elements;

Securely control IoT edge devices from anywhere   Connect a Device