0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

explicitly use mongo:: for this example for clarity

This commit is contained in:
Eliot Horowitz 2009-01-15 11:38:32 -05:00
parent db0b2adb69
commit 2dcdaa494a

View File

@ -8,11 +8,8 @@
#include "mongo/client/dbclient.h"
using namespace std;
using namespace mongo;
void insert( DBClientConnection & conn , const char * name , int num ) {
BSONObjBuilder obj;
void insert( mongo::DBClientConnection & conn , const char * name , int num ) {
mongo::BSONObjBuilder obj;
obj.append( "name" , name );
obj.append( "num" , num );
conn.insert( "test.people" , obj.doneAndDecouple() );
@ -20,7 +17,7 @@ void insert( DBClientConnection & conn , const char * name , int num ) {
int main() {
DBClientConnection conn;
mongo::DBClientConnection conn;
string errmsg;
if ( ! conn.connect( "127.0.0.1" , errmsg ) ) {
cout << "couldn't connect : " << errmsg << endl;
@ -28,35 +25,35 @@ int main() {
}
{ // clean up old data from any previous tests
BSONObjBuilder query;
mongo::BSONObjBuilder query;
conn.remove( "test.people" , query.doneAndDecouple() );
}
insert( conn , "eliot" , 15 );
insert( conn , "sara" , 23 );
{
BSONObjBuilder query;
auto_ptr<DBClientCursor> cursor = conn.query( "test.people" , query.doneAndDecouple() );
mongo::BSONObjBuilder query;
auto_ptr<mongo::DBClientCursor> cursor = conn.query( "test.people" , query.doneAndDecouple() );
cout << "using cursor" << endl;
while ( cursor->more() ) {
BSONObj obj = cursor->next();
mongo::BSONObj obj = cursor->next();
cout << "\t" << obj.jsonString() << endl;
}
}
{
BSONObjBuilder query;
mongo::BSONObjBuilder query;
query.append( "name" , "eliot" );
BSONObj res = conn.findOne( "test.people" , query.doneAndDecouple() );
mongo::BSONObj res = conn.findOne( "test.people" , query.doneAndDecouple() );
cout << res.isEmpty() << "\t" << res.jsonString() << endl;
}
{
BSONObjBuilder query;
mongo::BSONObjBuilder query;
query.append( "name" , "asd" );
BSONObj res = conn.findOne( "test.people" , query.doneAndDecouple() );
mongo::BSONObj res = conn.findOne( "test.people" , query.doneAndDecouple() );
cout << res.isEmpty() << "\t" << res.jsonString() << endl;
}