AnyBSONValue
public struct AnyBSONValue : Codable, Equatable, Hashable
A struct wrapping a BSONValue
type that allows for encoding/
decoding BSONValue
s of unknown type.
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
Declaration
Swift
public func encode(to encoder: Encoder) throws
-
Declaration
Swift
public static func == (lhs: AnyBSONValue, rhs: AnyBSONValue) -> Bool
-
Initializes a new
AnyBSONValue
from aDecoder
.Caveats for usage with
Decoder
s other than MongoSwift’sBSONDecoder
- 1) This method does not support initializing anAnyBSONValue
wrapping aDate
. This is because, in non-BSON formats,Date
s are encoded as other types such asDouble
orString
. We have no way of knowing which type is the intended one when decoding to aDocument
, asDocument
s can contain anyBSONValue
type, so for simplicity we always go with aDouble
or aString
over aDate
. 2) Numeric values will be attempted to be decoded in the following order of types:Int
,Int32
,Int64
,Double
. The first one that can successfully represent the value with no loss of precision will be used.Throws
DecodingError
if aBSONValue
could not be decoded from the given decoder (which is not aBSONDecoder
).DecodingError
if a BSON datetime is encountered but a non-default date decoding strategy was set on the decoder (which is aBSONDecoder
).
Declaration
Swift
public init(from decoder: Decoder) throws