playing with BSONObjBuilder stream for building

and an example
This commit is contained in:
Eliot Horowitz
2009-01-14 09:40:54 -05:00
parent 57eeff38ec
commit bf7edfbae5
3 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
// second.cpp
#include <iostream>
#include "mongo/client/dbclient.h"
using namespace std;
int main(){
DBClientConnection conn;
string errmsg;
if ( ! conn.connect( "127.0.0.1" , errmsg ) ){
cout << "couldn't connect : " << errmsg << endl;
throw -11;
}
const char * ns = "test.second";
conn.remove( ns , emptyObj );
conn.insert( ns , BUILDOBJ( "name" << "eliot" << "num" << 17 ) );
conn.insert( ns , BUILDOBJ( "name" << "sara" << "num" << 24 ) );
auto_ptr<DBClientCursor> cursor = conn.query( ns , emptyObj );
cout << "using cursor" << endl;
while ( cursor->more() ){
BSONObj obj = cursor->next();
cout << "\t" << obj.jsonString() << endl;
}
}