BSONValue

public protocol BSONValue

A protocol all types representing BSONTypes must implement.

  • The BSONType of this value.

    Declaration

    Swift

    var bsonType: BSONType { get }
  • Given the DocumentStorage backing a Document, appends this BSONValue to the end.

    Throws

    Throws:

    • RuntimeError.internalError if the DocumentStorage would exceed the maximum size by encoding this key-value pair.
    • UserError.logicError if the value is an Array and it contains a non-BSONValue element.

    Declaration

    Swift

    func encode(to storage: DocumentStorage, forKey key: String) throws

    Parameters

    storage

    A DocumentStorage to write to.

    key

    A String, the key under which to store the value.

  • bsonEquals(_:) Default implementation

    Function to test equality with another BSONValue. This function tests for exact BSON equality. This means that differing types with equivalent value are not equivalent.

    e.g. 4.0 (Double) != 4 (Int)

    Default Implementation

    Default implementation of bsonEquals for BSONValues that conform to Equatable.

    Declaration

    Swift

    func bsonEquals(_ other: BSONValue?) -> Bool

    Return Value

    true if self is equal to rhs, false otherwise.

  • Given a DocumentIterator known to have a next value of this type, initializes the value.

    Throws

    UserError.logicError if the current type of the DocumentIterator does not correspond to the associated type of this BSONValue.

    Declaration

    Swift

    static func from(iterator iter: DocumentIterator) throws -> Self