AnyBSONValue

public struct AnyBSONValue : Codable, Equatable, Hashable

A struct wrapping a BSONValue type that allows for encoding/ decoding BSONValues of unknown type.

  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)
  • The BSONValue wrapped by this struct.

    Declaration

    Swift

    public let value: BSONValue
  • Initializes a new AnyBSONValue wrapping the provided BSONValue.

    Declaration

    Swift

    public init(_ value: BSONValue)
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws
  • Declaration

    Swift

    public static func == (lhs: AnyBSONValue, rhs: AnyBSONValue) -> Bool
  • Initializes a new AnyBSONValue from a Decoder.

    Caveats for usage with Decoders other than MongoSwift’s BSONDecoder - 1) This method does not support initializing an AnyBSONValue wrapping a Date. This is because, in non-BSON formats, Dates are encoded as other types such as Double or String. We have no way of knowing which type is the intended one when decoding to a Document, as Documents can contain any BSONValue type, so for simplicity we always go with a Double or a String over a Date. 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 a BSONValue could not be decoded from the given decoder (which is not a BSONDecoder).
    • DecodingError if a BSON datetime is encountered but a non-default date decoding strategy was set on the decoder (which is a BSONDecoder).

    Declaration

    Swift

    public init(from decoder: Decoder) throws