Use type int for count

This commit is contained in:
fbraem 2015-03-21 21:57:01 +01:00
parent 65c704ea90
commit 4c4ab51a2c
3 changed files with 10 additions and 8 deletions

View File

@ -45,7 +45,7 @@ public:
virtual ~Database(); virtual ~Database();
/// Destructor /// Destructor
double count(Connection& connection, const std::string& collectionName) const; int count(Connection& connection, const std::string& collectionName) const;
/// Sends a count request for the given collection to MongoDB. When /// Sends a count request for the given collection to MongoDB. When
/// the command fails, -1 is returned. /// the command fails, -1 is returned.

View File

@ -32,7 +32,7 @@ Database::~Database()
} }
double Database::count(Connection& connection, const std::string& collectionName) const int Database::count(Connection& connection, const std::string& collectionName) const
{ {
Poco::SharedPtr<Poco::MongoDB::QueryRequest> countRequest = createCountRequest(collectionName); Poco::SharedPtr<Poco::MongoDB::QueryRequest> countRequest = createCountRequest(collectionName);
@ -42,7 +42,7 @@ double Database::count(Connection& connection, const std::string& collectionName
if ( response.documents().size() > 0 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[0]; Poco::MongoDB::Document::Ptr doc = response.documents()[0];
return doc->get<double>("n"); return doc->get<int>("n");
} }
return -1; return -1;

View File

@ -221,7 +221,8 @@ void MongoDBTest::testCountCommand()
if ( response.documents().size() > 0 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[0]; Poco::MongoDB::Document::Ptr doc = response.documents()[0];
double count = doc->get<double>("n"); std::cout << doc->toString() << std::endl;
int count = doc->get<int>("n");
assert(count == 1); assert(count == 1);
} }
else else
@ -248,7 +249,7 @@ void MongoDBTest::testDBCountCommand()
if ( response.documents().size() > 0 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[0]; Poco::MongoDB::Document::Ptr doc = response.documents()[0];
double count = doc->get<double>("n"); int count = doc->get<int>("n");
assert(count == 1); assert(count == 1);
} }
else else
@ -267,7 +268,7 @@ void MongoDBTest::testDBCount2Command()
} }
Poco::MongoDB::Database db("team"); Poco::MongoDB::Database db("team");
double count = db.count(_mongo, "players"); int count = db.count(_mongo, "players");
assert(count == 1); assert(count == 1);
} }
@ -305,7 +306,8 @@ void MongoDBTest::testCursorRequest()
} }
_mongo.sendRequest(*insertRequest); _mongo.sendRequest(*insertRequest);
double count = db.count(_mongo, "numbers"); int count = db.count(_mongo, "numbers");
std::cout << "count= " << count << std::endl;
assert(count == 10000); assert(count == 10000);
Poco::MongoDB::Cursor cursor("team", "numbers"); Poco::MongoDB::Cursor cursor("team", "numbers");
@ -390,7 +392,7 @@ void MongoDBTest::testConnectionPool()
if ( response.documents().size() > 0 ) if ( response.documents().size() > 0 )
{ {
Poco::MongoDB::Document::Ptr doc = response.documents()[0]; Poco::MongoDB::Document::Ptr doc = response.documents()[0];
double count = doc->get<double>("n"); int count = doc->get<int>("n");
assert(count == 1); assert(count == 1);
} }
else else