Uploaded image for project: 'Swift Driver'
  1. Swift Driver
  2. SWIFT-273

Provide a cleaner way to read fields in nested documents

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      Currently, if you want to access a field in a nested document, you must do something like

      let a = doc["a"]?.documentValue?["b"]

      It would be nice if users could instead do something like doc["a"]["b"].

      However, this is not possible right now, as the subscript getter returns a BSON, and BSON objects are not subscriptable.

      We could consider making BSON subscriptable. However, it's not clear what the behavior should be when a user tries to subscript something that isn't actually a document, for example, a String

      If we do implement this via subscript, analogous changes should be made to the dynamicMemberLookup behavior, to allow users to do doc.a.b etc.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              kaitlin.mahar Kaitlin Mahar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: