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

Add a "bson.RawArray" type to improve BSON array lookup API

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.0
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Major Change
    • Not Needed
    • Hide

      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?

      Show
      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?

      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.

            Assignee:
            preston.vasquez@mongodb.com Preston Vasquez
            Reporter:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: