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

Provide a cleaner way to read fields in nested documents

    XMLWordPrintable

Details

    • Improvement
    • Status: Backlog
    • Major - P3
    • Resolution: Unresolved
    • None
    • None
    • None

    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

              Unassigned Unassigned
              kaitlin.mahar@mongodb.com Kaitlin Mahar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: