0

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

1 Answer 1

1

conn is a pointer to a DBClientBase, you should use -> instead:

conn->insert("db.coll", p, 0);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.