-
Type: New Feature
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 0.0.2
-
Component/s: BSON
Currently, bson.Document.Lookup returns a *bson.Element and an error. This represents a shift from both the way that a Go map functions and the way the bson.Value, bson.ElementConstructor, and bson.ValueConstructor types function. All three of those types support a single value and dual value access method, e.g. bson.Value.Boolean and bson.Value.BooleanOK.
To better align to the semantics of the other types in the package, the bson.Document type should have two lookup functions, bson.Document.Lookup and bson.Document.LookupErr. In the case where an element does not exist, bson.Document.Lookup return nil. Since the map type in Go also supports accessing a nil map, we should support this as well. For the Lookup, LookupErr, ElementAt, and ElementAtOK methods return a nil element if the *Document is nil. In the case of LookupErr return an ErrNilDocument error and in the case of ElementAtOK return false.
Finally, the Lookup method does not currently support an empty string. There is nothing in BSON the precludes a key from being empty, so add support for empty strings with Lookup and LookupErr.
- related to
-
GODRIVER-412 BSON public API improvements
- Released