Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-360

Correct semantics of bson.Document.Lookup method

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.0.6
    • 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.

            Assignee:
            sam.kleinman Sam Kleinman (Inactive)
            Reporter:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: