mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
27 lines
548 B
C++
27 lines
548 B
C++
#include <iostream>
|
|
#include "../../client/dbclient.h"
|
|
|
|
// g++ -I ../.. -L ../.. tutorial.cpp -lmongoclient -lboost_thread -lboost_filesystem
|
|
|
|
using namespace mongo;
|
|
|
|
void run() {
|
|
DBClientConnection c;
|
|
c.connect("192.168.58.1");
|
|
cout << "connected ok" << endl;
|
|
BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
|
|
c.insert("tutorial.persons", p);
|
|
|
|
cout << "count:" << c.count("tutorial.persons") << endl;
|
|
}
|
|
|
|
int main() {
|
|
try {
|
|
run();
|
|
}
|
|
catch( DBException &e ) {
|
|
cout << "caught " << e.what() << endl;
|
|
}
|
|
return 0;
|
|
}
|