title: How to get OID of a BSON object as a hex string?
body: <p>I am using the <code>mongo-cxx</code> driver trying to convert the object ID of a <code>BSON</code> object to a string</p>
  
  <pre><code>BSONObj r=some_function();
  BSONElement oi;
  r.getObjectID(oi);
  OID o=oi.__oid();
  cout&lt;&lt;"oid:"&lt;&lt;o.toString()&lt;&lt;endl;`
  </code></pre>
  
  <p>I am sure that the <code>BSONObj</code> has valid data but I get the following error:</p>
  
  <blockquote>
    <p>BSONElement: bad type #somenumber</p>
  </blockquote>