[GODRIVER-1639] Add a "bson.RawArray" type to improve BSON array lookup API Created: 05/Jun/20  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: Major - P3
Reporter: Divjot Arora (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by GODRIVER-2443 Make Distinct return a decodable stru... Blocked
Related
related to GODRIVER-2863 Improve BSON RawValue type conversion... Backlog
is related to GODRIVER-2663 Deprecate "bson.Raw" APIs to support ... Closed
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   

Because arrays are BSON docs with integral keys, arrays can be accessed using bson.Raw.Lookup. For example, with this document,

{
    a: [{x: 1}, {y: 2},
}

this Lookup call can be used to get the value of a.1.y:

doc.Lookup("a", "1", "y")

This is technically correct, but having to pass in the string "1" is awkward. We should see if we can figure out a better way to do this. Maybe there should be a RawArray type so arrays are represented differently even though the underlying bytes are the same?

Another option is to have Lookup take ...interface{} so users can pass in either strings or integers and the driver can convert the ints to string. This could also be weird though because it makes the API less clear and we'd have to do a runtime check to reject things that aren't strings or ints.

Definition of done:

  • Add a new type RawArray to the bson package that has the same API as the bsoncore.Array type.
  • Update RawValue.Array and RawValue.ArrayOK to return a RawArray instead of a Raw.

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