本文整理汇总了C++中poco::mongodb::ResponseMessage::documents方法的典型用法代码示例。如果您正苦于以下问题:C++ ResponseMessage::documents方法的具体用法?C++ ResponseMessage::documents怎么用?C++ ResponseMessage::documents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::mongodb::ResponseMessage
的用法示例。
在下文中一共展示了ResponseMessage::documents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testCountCommand
void MongoDBTest::testCountCommand()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Poco::MongoDB::QueryRequest request("team.$cmd");
request.setNumberToReturn(1);
request.selector().add("count", std::string("players"));
Poco::MongoDB::ResponseMessage response;
_mongo.sendRequest(request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
double count = doc->get<double>("n");
assert(count == 1);
}
else
{
fail("Didn't get a response from the count command");
}
}
示例2: testDBCountCommand
void MongoDBTest::testDBCountCommand()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = db.createCountRequest("players");
Poco::MongoDB::ResponseMessage response;
_mongo.sendRequest(*request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
double count = doc->get<double>("n");
assert(count == 1);
}
else
{
fail("Didn't get a response from the count command");
}
}
示例3: testConnectionPool
void MongoDBTest::testConnectionPool()
{
Poco::Net::SocketAddress sa("localhost", 27017);
Poco::PoolableObjectFactory<Poco::MongoDB::Connection, Poco::MongoDB::Connection::Ptr> factory(sa);
Poco::ObjectPool<Poco::MongoDB::Connection, Poco::MongoDB::Connection::Ptr> pool(factory, 10, 15);
Poco::MongoDB::PooledConnection pooledConnection(pool);
Poco::MongoDB::QueryRequest request("team.$cmd");
request.setNumberToReturn(1);
request.selector().add("count", std::string("players"));
Poco::MongoDB::ResponseMessage response;
((Connection::Ptr) pooledConnection)->sendRequest(request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
assert(doc->getInteger("n") == 1);
}
else
{
fail("Didn't get a response from the count command");
}
}
示例4: testBuildInfo
void MongoDBTest::testBuildInfo()
{
Poco::MongoDB::QueryRequest request("team.$cmd");
request.setNumberToReturn(1);
request.selector().add("buildInfo", 1);
Poco::MongoDB::ResponseMessage response;
try
{
_mongo->sendRequest(request, response);
}
catch(Poco::NotImplementedException& nie)
{
std::cout << nie.message() << std::endl;
return;
}
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
std::cout << doc->toString(2);
}
else
{
fail("Didn't get a response from the buildinfo command");
}
}
示例5: authenticateMongoCR
bool MongoAuthentication::authenticateMongoCR(const std::string &user, const std::string &pwd)
{
bool ret = false;
_user = user;
_pwd = pwd;
try {
std::string nonce;
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
command->selector().add<Poco::Int32>("getnonce", 1);
command->setNumberToReturn(1);
Poco::MongoDB::ResponseMessage response;
_conn.sendRequest(*command, response);
if (response.documents().size() > 0) {
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
nonce = doc->get<std::string>("nonce", "");
std::string password = _user + ":mongo:" + _pwd;
Poco::MD5Engine md5;
md5.update(password);
std::string hashedPassword(Poco::DigestEngine::digestToHex(md5.digest()));
std::string key = nonce + _user + hashedPassword;
md5.reset();
md5.update(key);
std::string hashedKey(Poco::DigestEngine::digestToHex(md5.digest()));
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
command->selector()
.add<Poco::Int32>("authenticate", 1)
.add<std::string>("user", _user)
.add<std::string>("nonce", nonce)
.add<std::string>("key", hashedKey); // hex_md5( n.nonce + username + hex_md5( username + ":mongo:" + password ) )
_conn.sendRequest(*command, response);
if (response.documents().size() > 0 && response.documents()[0]->get<double>("ok")) {
ret = true;
}
}
} catch (Poco::Exception &) {
throw Poco::ApplicationException("auth failed.");
}
return ret;
}
示例6: count
double Database::count(Connection& connection, const std::string& collectionName) const
{
Poco::SharedPtr<Poco::MongoDB::QueryRequest> countRequest = createCountRequest(collectionName);
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*countRequest, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
return doc->get<double>("n");
}
return -1;
}
示例7: sample10
// SELECT DISTINCT birthyear FROM players WHERE birthyear > 1980
void sample10(Poco::MongoDB::Connection& connection)
{
std::cout << "*** SAMPLE 10 ***" << std::endl;
Poco::MongoDB::Database db("sample");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = db.createCommand();
command->selector()
.add("distinct", "players")
.add("key", "birthyear")
.addNewDocument("query")
.addNewDocument("birthyear")
.add("$gt", 1980);
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*command, response);
if ( response.hasDocuments() )
{
Poco::MongoDB::Array::Ptr values = response.documents()[0]->get<Poco::MongoDB::Array::Ptr>("values");
for(int i = 0; i < values->size(); ++i )
{
std::cout << values->get<int>(i) << std::endl;
}
}
}
示例8: testUUID
void MongoDBTest::testUUID()
{
Poco::MongoDB::Document::Ptr club = new Poco::MongoDB::Document();
club->add("name", std::string("Barcelona"));
Poco::UUIDGenerator generator;
Poco::UUID uuid = generator.create();
Poco::MongoDB::Binary::Ptr uuidBinary = new Poco::MongoDB::Binary(uuid);
club->add("uuid", uuidBinary);
Poco::MongoDB::InsertRequest request("team.club");
request.documents().push_back(club);
_mongo->sendRequest(request);
Poco::MongoDB::QueryRequest queryReq("team.club");
queryReq.selector().add("name" , std::string("Barcelona"));
Poco::MongoDB::ResponseMessage response;
_mongo->sendRequest(queryReq, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
try
{
std::string name = doc->get<std::string>("name");
assert(name.compare("Barcelona") == 0);
Poco::MongoDB::Binary::Ptr uuidBinary = doc->get<Binary::Ptr>("uuid");
assert(uuid == uuidBinary->uuid());
}
catch(Poco::NotFoundException& nfe)
{
fail(nfe.message() + " not found.");
}
}
else
{
fail("No document returned");
}
Poco::MongoDB::DeleteRequest delRequest("team.club");
delRequest.selector().add("name", std::string("Barcelona"));
_mongo->sendRequest(delRequest);
}
示例9: testQueryRequest
void MongoDBTest::testQueryRequest()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Poco::MongoDB::QueryRequest request("team.players");
request.selector().add("lastname" , std::string("Braem"));
request.setNumberToReturn(1);
Poco::MongoDB::ResponseMessage response;
_mongo.sendRequest(request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
try
{
std::string lastname = doc->get<std::string>("lastname");
assert(lastname.compare("Braem") == 0);
std::string firstname = doc->get<std::string>("firstname");
assert(firstname.compare("Franky") == 0);
Poco::Timestamp birthDateTimestamp = doc->get<Poco::Timestamp>("birthdate");
Poco::DateTime birthDate(birthDateTimestamp);
assert(birthDate.year() == 1969 && birthDate.month() == 3 && birthDate.day() == 9);
Poco::Timestamp lastupdatedTimestamp = doc->get<Poco::Timestamp>("lastupdated");
assert(doc->isType<NullValue>("unknown"));
bool active = doc->get<bool>("active");
assert(!active);
std::string id = doc->get("_id")->toString();
std::cout << id << std::endl;
}
catch(Poco::NotFoundException& nfe)
{
fail(nfe.message() + " not found.");
}
}
else
{
fail("No document returned");
}
}
示例10: testCursorRequest
void MongoDBTest::testCursorRequest()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
for(int i = 0; i < 10000; ++i)
{
Document::Ptr doc = new Document();
doc->add("number", i);
insertRequest->documents().push_back(doc);
}
_mongo.sendRequest(*insertRequest);
double count = db.count(_mongo, "numbers");
assert(count == 10000);
Poco::MongoDB::Cursor cursor("team", "numbers");
int n = 0;
Poco::MongoDB::ResponseMessage& response = cursor.next(_mongo);
while(1)
{
n += response.documents().size();
if ( response.cursorID() == 0 )
break;
response = cursor.next(_mongo);
}
std::cout << "n= " << n << std::endl;
assert(n == 10000);
Poco::MongoDB::QueryRequest drop("team.$cmd");
drop.setNumberToReturn(1);
drop.selector().add("drop", std::string("numbers"));
Poco::MongoDB::ResponseMessage responseDrop;
_mongo.sendRequest(drop, responseDrop);
if ( responseDrop.documents().size() > 0 )
{
std::cout << responseDrop.documents()[0]->toString(2) << std::endl;
}
}
示例11: getLastErrorDoc
Document::Ptr Database::getLastErrorDoc(Connection& connection) const
{
Document::Ptr errorDoc;
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createQueryRequest("$cmd");
request->setNumberToReturn(1);
request->selector().add("getLastError", 1);
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*request, response);
if ( response.documents().size() > 0 )
{
errorDoc = response.documents()[0];
}
return errorDoc;
}
示例12: testDBCountCommand
void MongoDBTest::testDBCountCommand()
{
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = db.createCountRequest("players");
Poco::MongoDB::ResponseMessage response;
_mongo->sendRequest(*request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
assert(doc->getInteger("n") == 1);
}
else
{
fail("Didn't get a response from the count command");
}
}
示例13: testCommand
void MongoDBTest::testCommand() {
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = db.createCommand();
command->selector().add("create", "fixCol")
.add("capped", true)
.add("max", 1024*1024)
.add("size", 1024);
Poco::MongoDB::ResponseMessage response;
_mongo->sendRequest(*command, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
}
else
{
Poco::MongoDB::Document::Ptr lastError = db.getLastErrorDoc(*_mongo);
fail(lastError->toString(2));
}
}
示例14: testCountCommand
void MongoDBTest::testCountCommand()
{
Poco::MongoDB::QueryRequest request("team.$cmd");
request.setNumberToReturn(1);
request.selector().add("count", std::string("players"));
Poco::MongoDB::ResponseMessage response;
_mongo->sendRequest(request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
assert(doc->getInteger("n") == 1);
}
else
{
fail("Didn't get a response from the count command");
}
}
示例15: testDBQueryRequest
void MongoDBTest::testDBQueryRequest()
{
Database db("team");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = db.createQueryRequest("players");
request->selector().add("lastname" , std::string("Braem"));
Poco::MongoDB::ResponseMessage response;
_mongo->sendRequest(*request, response);
if ( response.documents().size() > 0 )
{
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
try
{
std::string lastname = doc->get<std::string>("lastname");
assert(lastname.compare("Braem") == 0);
std::string firstname = doc->get<std::string>("firstname");
assert(firstname.compare("Franky") == 0);
Poco::Timestamp birthDateTimestamp = doc->get<Poco::Timestamp>("birthdate");
Poco::DateTime birthDate(birthDateTimestamp);
assert(birthDate.year() == 1969 && birthDate.month() == 3 && birthDate.day() == 9);
Poco::Timestamp lastupdatedTimestamp = doc->get<Poco::Timestamp>("lastupdated");
assert(doc->isType<NullValue>("unknown"));
std::string id = doc->get("_id")->toString();
}
catch(Poco::NotFoundException& nfe)
{
fail(nfe.message() + " not found.");
}
}
else
{
fail("No document returned");
}
}