MongoDB native: is there any difference between toString and toHexString methods?
toHexString
method returns the ObjectID id as a 24 byte hex string representation.
// Create a new ObjectIDvar objectId = new ObjectID();// Verify that the hex string is 24 characters longassert.equal(24, objectId.toHexString().length);
You won't need to base64 encode the result of calling toString
on an ObjectId
as it's returned as a hex number already. You could also call: _id.toHexString()
to get the hex value directly.
Click this link to see MongoDB source (toString just wraps toHexString).