MongoCursor
A cursor returned from a query, used to iterate over the results. Used in find, aggregate, and listCollections. This is a reference type, and should be used as such.
Cursor.swift:14final class MongoCursor
let cursor = collection.find(…) while let doc = try await cursor.next() { print(doc) }
Citizens in MongoClient
Conformances
Type members
init(reply: MongoCursorResponse.Cursor, in: MongoNamespace, connection: MongoConnection, hoppedEventLoop: EventLoop?, session: MongoClientSession, transaction: MongoTransaction?, traceLabel: String?, context: ServiceContext?
)
Instance members
var closeFuture: EventLoopFuture<Void>
A future that will be completed when the cursor is closed
let connection: MongoConnection
The connection this cursor is using to communicate with the server
var hoppedEventLoop: EventLoop?
The event loop this cursor is bound to and will return results on
var id: Int64
The id of the cursor, used for
getMore
requestsvar isDrained: Bool
Whether the cursor has been closed, either by the user or by the server
var maxTimeMS: Int32?
The maximum amount of time to allow the server to spend on this cursor
let namespace: MongoNamespace
The namespace this cursor is reading from
var readConcern: ReadConcern?
The read concern to use for this cursor
let session: MongoClientSession?
The session this cursor is associated with, if any
let transaction: MongoTransaction?
The transaction this cursor is associated with, if any
func close(
) async throws Closes the cursor stopping any further data from being read
func getMore(batchSize: Int
) async throws -> [Document] Performs a
GetMore
command on the database, requesting the next batch of items
Available in MongoKitten
Conformances
protocol Copyable
A type whose values can be implicitly or explicitly copied.
protocol Escapable
protocol QueryCursor
A cursor with results from a query. Implemented by
FindCursor
andAggregateCursor
.
Typealiases
Instance members
var eventLoop: EventLoop
func drain(
) async throws -> [Document] Collects all results into an array, until the cursor is drained
func execute(
) async throws -> FinalizedCursor<MongoCursor> func getConnection(
) async throws -> MongoConnection func transformElement(Document
) throws -> Document
Instance features
func decode<D>(D.Type, using: BSONDecoder
) -> MappedCursor<Self, D> Generates a
MappedCursor
with decoded instances ofD
as its element type, using the givendecoder
.func drain(failable: Bool
) async throws -> [Element] Executes the cursor and returns all results as an array Please be aware that this may consume a large amount of memory or time with a large number of results
func firstResult(
) async throws -> Element? Executes the cursor and returns the first result Always uses a batch size of 1
func forEach(failable: Bool, handler: @escaping (Element) async throws -> Void
) -> Task<Void, Error> Executes the given
handler
for every element of the cursor.func map<E>(transform: @escaping (Element) async throws -> E
) -> MappedCursor<Self, E> Returns a new cursor with the results of mapping the given closure over the cursor’s elements. This operation is lazy.