Library: MongoDB
Package: MongoDB
Header: Poco/MongoDB/Document.h
Represents a BSON document
Known Derived Classes: Cursor, Array
Member Functions: add, addElement, addNewDocument, clear, elementNames, empty, exists, get, isType, read, size, toString, write
typedef SharedPtr < Document > Ptr;
typedef std::vector < Document::Ptr > Vector;
Document();
Constructor
virtual ~Document();
Destructor
template < typename T > Document & add(
const std::string & name,
T value
);
Creates an element with the given name and value and The active document is returned to allow chaining of the add methods.
Document & add(
const std::string & name,
const char * value
);
Creates an element with the given name and value and The active document is returned to allow chaining of the add methods.
Document & addElement(
Element::Ptr element
);
Add an element to the document. The active document is returned to allow chaining of the add methods.
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.
void clear();
Removes all elements from the document.
void elementNames(
std::vector < std::string > & keys
) const;
Puts all element names into std::vector.
bool empty() const;
Returns true when the document doesn't contain any documents.
bool exists(
const std::string & name
);
Returns true when the document has an element with the given name
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.
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.
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.
template < typename T > bool isType(
const std::string & name
);
Returns true when the type of the element equals the TypeId of ElementTrait
void read(
BinaryReader & reader
);
Reads a document from the reader
size_t size() const;
Returns the number of elements in the document.
virtual std::string toString(
int indent = 0
) const;
Returns a String representation of the document.
void write(
BinaryWriter & writer
);
Writes a document to the reader
ElementSet _elements;