cast(with:)

Promotes a nil result to a thrown TypecastError.

BSON.AnyValue.swift:151
func cast<T>(with cast: (`Self`) throws -> T?) throws -> T

Throws

A TypecastError if the given curried method returns nil.

If T conforms to BSONDecodable, prefer calling its throwing init(bson:) to calling this method directly.