[GODRIVER-2796] Return an error if attempting to decode a BSON object ID as a Go string Created: 04/Apr/23  Updated: 08/Jan/24

Status: Backlog
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Go Driver 2.0 BSON
Quarter: FY24Q3
Backwards Compatibility: Major Change
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Currently, the Go BSON library allows decoding a BSON ObjectID into a Go string value by default. The resulting string is the hexadecimal representation of the BSON ObjectID bytes. If the DecodeObjectIDAsHex option is disabled (enabled by default), the BSON ObjectID is decoded as the UTF-8 representation of the raw ObjectID bytes, which results in a garbled and unusable string. Instead of defaulting to decoding to a hexadecimal string value, we should return an error by default, and allow decoding to a hexadecimal string as an optional fallback.

Definition of done:

  • Update the logic here to return an error by default.
  • Add a Decoder.ObjectIDAsHexString method that enables decoding a BSON ObjectID as a hexadecimal string instead of returning an error.

Generated at Thu Feb 08 08:39:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.