MongoCursor

public class MongoCursor<T> : Sequence, IteratorProtocol where T : Decodable, T : Encodable

A MongoDB cursor.

  • Closes the cursor.

    Declaration

    Swift

    public func close()
  • Returns the next Document in this cursor or nil, or throws an error if one occurs – compared to next(), which returns nil and requires manually checking for an error afterward.

    Throws

    • ServerError.commandError if an error occurs on the server while iterating the cursor.
    • UserError.logicError if this function is called after the cursor has died.
    • UserError.logicError if this function is called and the session associated with this cursor is inactive.
    • DecodingError if an error occurs decoding the server’s response.

    Declaration

    Swift

    public func nextOrError() throws -> T?

    Return Value

    the next Document in this cursor, or nil if at the end of the cursor

  • The error that occurred while iterating this cursor, if one exists. This should be used to check for errors after next() returns nil.

    Declaration

    Swift

    public var error: Error? { get }
  • Returns the next Document in this cursor, or nil. Once this function returns nil, the caller should use the .error property to check for errors.

    Declaration

    Swift

    public func next() -> T?