-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: BSON
-
None
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.
- is depended on by
-
GODRIVER-2443 Make Distinct return a decodable struct "[]any"
- Closed
- is related to
-
GODRIVER-2663 Deprecate "bson.Raw" APIs to support merge with "bsoncore.Document" API
- Closed
- related to
-
GODRIVER-2863 Improve BSON RawValue type conversion APIs
- Backlog