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

Array should conditionally conform to BSONValue

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 0.2.0
    • None

    Description

      An array should only be a BsonValue if all of its elements are BsonValue?s. Now that Swift 4.2 completes conditional conformance, we can provide better type safety around what arrays can be added to documents. 

      We currently just silently fail and convert anything that couldn't be cast to a BsonValue to nil.

      For example:

       

      let arr: [Int16] = [1, 2, 3, 4]
       var doc = Document()
       doc["a"] = arr
      print(doc) // { "a" : [ null, null, null, null ] }
      

       
      NOTE: kaitlin.mahar brought up a good point about how we may want to instead support arrays of Codable ([Codable]).
       

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: