diff options
| author | Apollon Oikonomopoulos <apoikos@debian.org> | 2016-01-14 00:10:06 +0200 |
|---|---|---|
| committer | Apollon Oikonomopoulos <apollon@skroutz.gr> | 2016-01-14 00:10:06 +0200 |
| commit | 374e1947abcd3e127a2a613aff73ecffdb9199ea (patch) | |
| tree | d83973c3c9802450acd5b5e86fe0d4e8e60a3a1b /src/mongo/client/examples/whereExample.cpp | |
| parent | 65585c90b12d6523bea75a2aebaae2a2fdf9e641 (diff) | |
Imported Upstream version 2.6.11upstream/2.6.11
Diffstat (limited to 'src/mongo/client/examples/whereExample.cpp')
| -rw-r--r-- | src/mongo/client/examples/whereExample.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/mongo/client/examples/whereExample.cpp b/src/mongo/client/examples/whereExample.cpp index a2f98d7f71d..23afe8fbe0e 100644 --- a/src/mongo/client/examples/whereExample.cpp +++ b/src/mongo/client/examples/whereExample.cpp @@ -20,6 +20,10 @@ #include "mongo/client/dbclient.h" +#ifndef verify +# define verify(x) MONGO_verify(x) +#endif + using namespace std; using namespace mongo; @@ -27,16 +31,25 @@ int main( int argc, const char **argv ) { const char *port = "27017"; if ( argc != 1 ) { - if ( argc != 3 ) - throw -12; + if ( argc != 3 ) { + cout << "need to pass port as second param" << endl; + return EXIT_FAILURE; + } port = argv[ 2 ]; } + + Status status = client::initialize(); + if ( !status.isOK() ) { + std::cout << "failed to initialize the client driver: " << status.toString() << endl; + return EXIT_FAILURE; + } + DBClientConnection conn; string errmsg; if ( ! conn.connect( string( "127.0.0.1:" ) + port , errmsg ) ) { cout << "couldn't connect : " << errmsg << endl; - throw -11; + return EXIT_FAILURE; } const char * ns = "test.where"; @@ -46,7 +59,11 @@ int main( int argc, const char **argv ) { conn.insert( ns , BSON( "name" << "eliot" << "num" << 17 ) ); conn.insert( ns , BSON( "name" << "sara" << "num" << 24 ) ); - auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObj() ); + std::auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObj() ); + if (!cursor.get()) { + cout << "query failure" << endl; + return EXIT_FAILURE; + } while ( cursor->more() ) { BSONObj obj = cursor->next(); @@ -58,6 +75,10 @@ int main( int argc, const char **argv ) { Query q = Query("{}").where("this.name == name" , BSON( "name" << "sara" )); cursor = conn.query( ns , q ); + if (!cursor.get()) { + cout << "query failure" << endl; + return EXIT_FAILURE; + } int num = 0; while ( cursor->more() ) { @@ -65,5 +86,7 @@ int main( int argc, const char **argv ) { cout << "\t" << obj.jsonString() << endl; num++; } - MONGO_verify( num == 1 ); + verify( num == 1 ); + + return EXIT_SUCCESS; } |
