I have written a C++ function to insert a new record into the document in a Mongodb database. However, I could not finish it. I am new to this API and seeking help.
My record into docuement would look like this. For now, I have written a mongo shell command to do this, but I want to achieve same using C++ API.
{ _id: ObjectId('5541578bcec7d8fd45839197'), id: "sensor1", name: "/temp/s/1", ap: { name: "/ap/1/access/1" } }
C++ API.
void
LocationDb::insert(string sensorId, string sensorName, string routerName) {
BSONObj sensorObj = BSONObjBuilder().genOID().append("id", sensorId) \
.append("name",sensorName).append("ap", "name", routerName).obj();
// This last append is not clear to me.
m_conn.insert("location_db.ldb", sensorObj);
}
Can someone please help with the correct API to achieve the above result?