fix sample

This commit is contained in:
Guenter Obiltschnig 2017-02-13 16:38:28 +01:00
parent fd2319d934
commit e84788f085

View File

@ -152,7 +152,7 @@ void sample2(Poco::MongoDB::Connection& connection)
cursor.query().returnFieldSelector().add("lastname", 1); cursor.query().returnFieldSelector().add("lastname", 1);
cursor.query().returnFieldSelector().add("birthyear", 1); cursor.query().returnFieldSelector().add("birthyear", 1);
Poco::MongoDB::ResponseMessage& response = cursor.next(connection); Poco::MongoDB::ResponseMessage& response = cursor.next(connection);
while(1) for (;;)
{ {
for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it) for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it)
{ {
@ -178,7 +178,7 @@ void sample3(Poco::MongoDB::Connection& connection)
Poco::MongoDB::Cursor cursor("sample", "players"); Poco::MongoDB::Cursor cursor("sample", "players");
Poco::MongoDB::ResponseMessage& response = cursor.next(connection); Poco::MongoDB::ResponseMessage& response = cursor.next(connection);
while(1) for (;;)
{ {
for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it) for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it)
{ {
@ -206,7 +206,7 @@ void sample4(Poco::MongoDB::Connection& connection)
cursor.query().selector().add("birthyear", 1978); cursor.query().selector().add("birthyear", 1978);
Poco::MongoDB::ResponseMessage& response = cursor.next(connection); Poco::MongoDB::ResponseMessage& response = cursor.next(connection);
while(1) for (;;)
{ {
for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it) for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it)
{ {
@ -234,10 +234,10 @@ void sample5(Poco::MongoDB::Connection& connection)
// When orderby is needed, use 2 separate documents in the query selector // When orderby is needed, use 2 separate documents in the query selector
cursor.query().selector().addNewDocument("$query").add("birthyear", 1987); cursor.query().selector().addNewDocument("$query").add("birthyear", 1987);
cursor.query().selector().addNewDocument("$orderby").add("lastname", 0); cursor.query().selector().addNewDocument("$orderby").add("lastname", 1);
Poco::MongoDB::ResponseMessage& response = cursor.next(connection); Poco::MongoDB::ResponseMessage& response = cursor.next(connection);
while(1) for (;;)
{ {
for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it) for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it)
{ {
@ -268,7 +268,7 @@ void sample6(Poco::MongoDB::Connection& connection)
.add("$lte", 1980); .add("$lte", 1980);
Poco::MongoDB::ResponseMessage& response = cursor.next(connection); Poco::MongoDB::ResponseMessage& response = cursor.next(connection);
while(1) for (;;)
{ {
for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it) for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it)
{ {
@ -322,7 +322,7 @@ void sample8(Poco::MongoDB::Connection& connection)
cursor.query().setNumberToReturn(10); cursor.query().setNumberToReturn(10);
cursor.query().setNumberToSkip(20); cursor.query().setNumberToSkip(20);
Poco::MongoDB::ResponseMessage& response = cursor.next(connection); Poco::MongoDB::ResponseMessage& response = cursor.next(connection);
while(1) for (;;)
{ {
for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it) for (Poco::MongoDB::Document::Vector::const_iterator it = response.documents().begin(); it != response.documents().end(); ++it)
{ {
@ -410,7 +410,7 @@ void sample11(Poco::MongoDB::Connection& connection)
if (response.hasDocuments()) if (response.hasDocuments())
{ {
std::cout << "Count: " << response.documents()[0]->get<double>("n") << std::endl; std::cout << "Count: " << response.documents()[0]->getInteger("n") << std::endl;
} }
} }
@ -453,6 +453,8 @@ int main(int argc, char** argv)
{ {
Poco::MongoDB::Connection connection("localhost", 27017); Poco::MongoDB::Connection connection("localhost", 27017);
try
{
sample1(connection); sample1(connection);
sample2(connection); sample2(connection);
sample3(connection); sample3(connection);
@ -466,6 +468,11 @@ int main(int argc, char** argv)
sample11(connection); sample11(connection);
sample12(connection); sample12(connection);
sample13(connection); sample13(connection);
}
catch (Poco::Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
}
return 0; return 0;
} }