0
而不是使用DBClientConnection類,我正在使用DBClientBase類。我成功地能夠連接到數據庫但無法插入文檔。如何在MongoDB C++驅動程序中使用DBClientBase類插入文檔?
這裏是我的代碼看起來喜歡 -
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);
的編譯器會發出錯誤request for member ‘insert’ in ‘conn’, which is of non-class type ‘mongo::DBClientBase*’
有一個例子某處如何使用DBClientBase類插入文件?
而且,我似乎無法找出什麼是在virtual void insert (const string &ns, BSONObj obj, int flags=0)
使用標誌提到here