[GODRIVER-360] Correct semantics of bson.Document.Lookup method Created: 11/Apr/18 Updated: 28/Oct/23 Resolved: 23/May/18 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | 0.0.2 |
| Fix Version/s: | 0.0.6 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Kristofer Brandow (Inactive) | Assignee: | Sam Kleinman (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | FreeMonitoring | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Epic Link: | GODRIVER BSON public API improvements | ||||||||
| Description |
|
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. |
| Comments |
| Comment by Githook User [ 22/May/18 ] | |
|
Author: {'username': 'tychoish', 'name': 'Sam Kleinman', 'email': 'sam@10gen.com'}Message: Change-Id: I48774e72943378695b1ac3ae31a53ad43c4fdce7 | |
| Comment by Kristofer Brandow (Inactive) [ 11/Apr/18 ] | |
|
To further align with the semantics of the map type, craiggwilson and jeff.yemin have suggested we have Lookup and LookupErr return a *bson.Value instead of a *bson.Element. To ensure that users can still retrieve a *bson.Element if they want to, additionally add a LookupElement method with the following signature:
|