hi, I am a develop from LeTV China.
I use mongo cxx client ver. legacy, and have a question with the oid of the insert operation.
In the github wiki, I have read below:
Use the GENOID helper to add an object id to your object. The server will add an _id automatically if it is not included explicitly.
BSONObj p = BSON( GENOID << "name" << "Joe" << "age" << 33 );
// result is:Unknown macro: { _id }BSONObj p = BSONObjBuilder().genOID().append("name","Joe").append("age",33).obj();
It means that mongo client will not generate the oid for me unless I included it explicitly in the BSONbuilder.
But in `insert_write_operation.cpp`, I found that mongo client will gerate oid for me automatically.
BSONObj InsertWriteOperation::_ensureId(const BSONObj& doc) { BSONElement id = doc.getField("_id"); if (!id.eoo()) { uassert(0, "value of _id element cannot contain any fields starting with $", !id.isABSONObj() || id.Obj().okForStorage()); return doc; } BSONObjBuilder bob; bob.append("_id", OID::gen()); bob.appendElements(doc); return bob.obj(); }
So, will the mongo client give the choice to user to select who will genrate the oid, from the mongo client or the mongo server.