Poco::MongoDB

class Database

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

Description

Database is a helper class for creating requests. MongoDB works with collection names and uses the part before the first dot as the name of the database.

Member Summary

Member Functions: count, createCommand, createCountRequest, createDeleteRequest, createInsertRequest, createQueryRequest, createUpdateRequest, ensureIndex, getLastError, getLastErrorDoc

Constructors

Database

Database(
    const std::string & db
);

Constructor

Destructor

~Database virtual

virtual ~Database();

Destructor

Member Functions

count

double count(
    Connection & connection,
    const std::string & collectionName
) const;

Sends a count request for the given collection to MongoDB. When the command fails, -1 is returned.

createCommand inline

Poco::SharedPtr < Poco::MongoDB::QueryRequest > createCommand() const;

Creates a QueryRequest for a command.

createCountRequest

Poco::SharedPtr < Poco::MongoDB::QueryRequest > createCountRequest(
    const std::string & collectionName
) const;

Creates a QueryRequest to count the given collection. The collectionname must not contain the database name!

createDeleteRequest inline

Poco::SharedPtr < Poco::MongoDB::DeleteRequest > createDeleteRequest(
    const std::string & collectionName
) const;

Creates a DeleteRequest to delete documents in the given collection. The collectionname must not contain the database name!

createInsertRequest inline

Poco::SharedPtr < Poco::MongoDB::InsertRequest > createInsertRequest(
    const std::string & collectionName
) const;

Creates an InsertRequest to insert new documents in the given collection. The collectionname must not contain the database name!

createQueryRequest inline

Poco::SharedPtr < Poco::MongoDB::QueryRequest > createQueryRequest(
    const std::string & collectionName
) const;

Creates a QueryRequest. The collectionname must not contain the database name!

createUpdateRequest inline

Poco::SharedPtr < Poco::MongoDB::UpdateRequest > createUpdateRequest(
    const std::string & collectionName
) const;

Creates an UpdateRequest. The collectionname must not contain the database name!

ensureIndex

Poco::MongoDB::Document::Ptr ensureIndex(
    Connection & connection,
    const std::string & collection,
    const std::string & indexName,
    Poco::MongoDB::Document::Ptr keys,
    bool unique = false,
    bool background = false,
    int version = 0,
    int ttl = 0
);

Creates an index. The document returned is the result of a getLastError call. For more info look at the ensureIndex information on the MongoDB website.

getLastError

std::string getLastError(
    Connection & connection
) const;

Sends the getLastError command to the database and returns the err element from the error document. When err is null, an empty string is returned.

getLastErrorDoc

Document::Ptr getLastErrorDoc(
    Connection & connection
) const;

Sends the getLastError command to the database and returns the document