Instead of using DBClientConnection class, I am using DBClientBase class. I am successfully able to connect to the DB but not able to insert a document.
Here is how my code looks like-
DBClientBase *conn = NULL;
string err_msg;
ConnectionString cs = ConnectionString::parse(connString, err_msg);
if (!cs.isValid()) {
throw "bad: " + err_msg;
}
try {
conn = cs.connect(err_msg);
} catch (DBException &e) {
cout << "caught " << err_msg << endl;
return 1;
}
if (!conn){
cout<<"Unable to connect to DB"<<endl;
return 1;
}
BSONObjBuilder b;
b.append("name", "Joe");
b.append("age", 33);
BSONObj p = b.obj();
conn.insert("db.coll",p,0);
the compiler gives error request for member ‘insert’ in ‘conn’, which is of non-class type ‘mongo::DBClientBase*’
Is there an example somewhere on how to use DBClientBase class to insert documents?
Also, I cannot seem to find what is the use of flags in virtual void insert (const string &ns, BSONObj obj, int flags=0) as mentioned here