Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
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]).