RemoteMongoReadOperation

public class RemoteMongoReadOperation<T> where T : Decodable, T : Encodable

Represents a find or aggregate operation against a MongoDB collection. Use the methods in this class to execute the operation and retrieve the results.

  • Executes the operation and returns the first document in the result.

    Declaration

    Swift

    public func first(_ completionHandler: @escaping (StitchResult<T?>) -> Void)

    Parameters

    completionHandler

    The completion handler to call when the operation is completed or if the operation fails. This handler is executed on a non-main global DispatchQueue. If the operation is successful, the result will contain an optional T indicating the first document in the result. the document will be nil if the result was empty.

  • Executes the operation and returns the result as an array.

    Declaration

    Swift

    public func toArray(_ completionHandler: @escaping (StitchResult<[T]>) -> Void)

    Parameters

    completionHandler

    The completion handler to call when the operation is completed or if the operation fails. This handler is executed on a non-main global DispatchQueue. If the operation is successful, the result will contain the documents in the result as an array.

  • Executes the operation and returns the result as an array. Deprecated in favor of toArray.

    Declaration

    Swift

    @available(*, deprecated, message: "use toArray instead")
    public func asArray(_ completionHandler: @escaping (StitchResult<[T]>) -> Void)

    Parameters

    completionHandler

    The completion handler to call when the operation is completed or if the operation fails. This handler is executed on a non-main global DispatchQueue. If the operation is successful, the result will contain the documents in the result as an array.

  • Executes the operation and returns a cursor to its resulting documents.

    Declaration

    Swift

    public func iterator(_ completionHandler: @escaping (StitchResult<RemoteMongoCursor<T>>) -> Void)

    Parameters

    completionHandler

    The completion handler to call when the operation is completed or if the operation fails. This handler is executed on a non-main global DispatchQueue. If the operation is successful, the result will contain an asynchronously iterating cursor to the documents in the result.