2009-02-06 22:58:46 +01:00
|
|
|
#include <iostream>
|
2009-02-08 22:02:48 +01:00
|
|
|
#include "../../client/dbclient.h"
|
2009-02-06 22:58:46 +01:00
|
|
|
|
|
|
|
// g++ -I ../.. -L ../.. tutorial.cpp -lmongoclient -lboost_thread -lboost_filesystem
|
|
|
|
|
|
|
|
using namespace mongo;
|
|
|
|
|
|
|
|
void run() {
|
|
|
|
DBClientConnection c;
|
2009-02-09 22:24:47 +01:00
|
|
|
c.connect("192.168.58.1");
|
2009-02-08 22:02:48 +01:00
|
|
|
cout << "connected ok" << endl;
|
2009-02-09 03:18:38 +01:00
|
|
|
BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
|
|
|
|
c.insert("tutorial.persons", p);
|
2009-02-09 21:38:26 +01:00
|
|
|
|
2009-02-09 22:24:47 +01:00
|
|
|
cout << "count:" << c.count("tutorial.persons") << endl;
|
2009-02-06 22:58:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
try {
|
|
|
|
run();
|
2009-02-08 22:02:48 +01:00
|
|
|
}
|
|
|
|
catch( DBException &e ) {
|
2009-02-06 22:58:46 +01:00
|
|
|
cout << "caught " << e.what() << endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|