Advertisement
Guest User

Untitled

a guest
Jan 10th, 2012
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. void SaveDoc(DBClientConnection &conn)
  2.   {
  3.  
  4.     b.append("data", data);
  5.     BSONObj p = b.obj();
  6.    
  7.     if (conn.isFailed()==false){
  8.         try{
  9.             conn.insert("db.collection",p);
  10.            } catch (std::exception& e)
  11.             {
  12.                 std::cerr << "Exception occured while inserting log: " << e.what() << "\n";
  13.             }
  14.       } else {
  15.          cout<<"Not connected to DB!"<<endl;
  16.          try{
  17.           cout<<"Trying to re-connect to DB"<<endl;
  18.           conn.connect("localhost");          }
  19.           catch (std::exception& e)
  20.             {
  21.                cout<< "Exception found while reconnecting: " << e.what() << "\n";
  22.             }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement