Add createCommand method and rearrange code

This commit is contained in:
fbraem 2013-02-27 18:51:55 +01:00
parent 6a8b2c5a48
commit 2d3e78146d
2 changed files with 20 additions and 8 deletions

View File

@ -66,8 +66,8 @@ public:
/// the command fails, -1 is returned.
Poco::SharedPtr<Poco::MongoDB::QueryRequest> createQueryRequest(const std::string& collectionName) const;
/// Creates a QueryRequest. The collectionname must not contain the database name!
Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCommand() const;
/// Creates a QueryRequest for a command.
Poco::SharedPtr<Poco::MongoDB::QueryRequest> createCountRequest(const std::string& collectionName) const;
@ -80,6 +80,10 @@ public:
/// The collectionname must not contain the database name!
Poco::SharedPtr<Poco::MongoDB::QueryRequest> createQueryRequest(const std::string& collectionName) const;
/// Creates a QueryRequest. The collectionname must not contain the database name!
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.
@ -97,6 +101,14 @@ private:
std::string _dbname;
};
inline Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createCommand() const
{
Poco::SharedPtr<Poco::MongoDB::QueryRequest> cmd = createQueryRequest("$cmd");
cmd->setNumberToReturn(1);
return cmd;
}
}} // Namespace Poco::MongoDB
#endif // _MongoDB_Database_included

View File

@ -138,12 +138,6 @@ std::string Database::getLastError(Connection& connection) const
}
Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createQueryRequest(const std::string& collectionName) const
{
return new Poco::MongoDB::QueryRequest(_dbname + '.' + collectionName);
}
Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createCountRequest(const std::string& collectionName) const
{
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createQueryRequest("$cmd");
@ -159,4 +153,10 @@ Poco::SharedPtr<Poco::MongoDB::InsertRequest> Database::createInsertRequest(cons
}
Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createQueryRequest(const std::string& collectionName) const
{
return new Poco::MongoDB::QueryRequest(_dbname + '.' + collectionName);
}
}} // Namespace Poco::MongoDB