diff options
author | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2011-09-14 17:08:06 +0200 |
commit | 5d342a758c6095b4d30aba0750b54f13b8916f51 (patch) | |
tree | 762e9aa84781f5e3b96db2c02d356c29cf0217c0 /client/examples/insert_demo.cpp | |
parent | cbe2d992e9cd1ea66af9fa91df006106775d3073 (diff) | |
download | mongodb-5d342a758c6095b4d30aba0750b54f13b8916f51.tar.gz |
Imported Upstream version 2.0.0
Diffstat (limited to 'client/examples/insert_demo.cpp')
-rw-r--r-- | client/examples/insert_demo.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/client/examples/insert_demo.cpp b/client/examples/insert_demo.cpp new file mode 100644 index 0000000..14ac79e --- /dev/null +++ b/client/examples/insert_demo.cpp @@ -0,0 +1,47 @@ +/* + C++ client program which inserts documents in a MongoDB database. + + How to build and run: + + Using mongo_client_lib.cpp: + g++ -I .. -I ../.. insert_demo.cpp ../mongo_client_lib.cpp -lboost_thread-mt -lboost_filesystem + ./a.out +*/ + +#include <iostream> +#include "dbclient.h" // the mongo c++ driver + +using namespace std; +using namespace mongo; +using namespace bson; + +int main() { + try { + cout << "connecting to localhost..." << endl; + DBClientConnection c; + c.connect("localhost"); + cout << "connected ok" << endl; + + bo o = BSON( "hello" << "world" ); + + cout << "inserting..." << endl; + + time_t start = time(0); + for( unsigned i = 0; i < 1000000; i++ ) { + c.insert("test.foo", o); + } + + // wait until all operations applied + cout << "getlasterror returns: \"" << c.getLastError() << '"' << endl; + + time_t done = time(0); + time_t dt = done-start; + cout << dt << " seconds " << 1000000/dt << " per second" << endl; + } + catch(DBException& e) { + cout << "caught DBException " << e.toString() << endl; + return 1; + } + + return 0; +} |