In the MongoDB shell, if I type someDoc._id, Mongo replies with something like ObjectId(4f6b83af44c75956279e7777). How is that string generated from the ObjectId bytes?
Links to the javascript source for this are welcome, as are links to the source for other drivers.
Looks like that comes from
BSONElement::toString:And
__oid()gives you amongo::OIDand the<<operator callsstr:and that just calls
toHexLoweron the raw bytes:Finally,
toHexLowerdoes this:The stringification isn’t done in JavaScript, it is done in C++.
The above uses the 2.0 branch of MongoDB but the (current) master is the same (or nearly so).