MongoCursor
public class MongoCursor<T> : CursorProtocol where T : Decodable, T : Encodable
A MongoDB cursor.
Note that the next method blocks until a result is received or the cursor is exhausted, so methods inherited from
Sequence that iterate over the entire sequence may block indefinitely when used on tailable cursors (e.g.
reduce).
It is safe to kill(...) a MongoCursor from another thread while it is blocked waiting on results, however.
-
Indicates whether this cursor has the potential to return more data.
This method is mainly useful if this cursor is tailable, since in that case
tryNextmay return more results even after returningnil.If this cursor is non-tailable, it will always be dead after either
tryNextreturnsnilor a non-DecodingErrorerror.This cursor will be dead after
nextreturnsnilor a non-DecodingErrorerror, regardless of theMongoCursorType.This cursor may still be alive after
nextortryNextreturns aDecodingError.Declaration
Swift
public func isAlive() -> Bool -
Returns the ID used by the server to track the cursor.
nilonce all results have been fetched from the server.Declaration
Swift
public var id: Int64? { get } -
Returns a
Resultcontaining the nextTin this cursor, an error if one occurred, ornilif the cursor is exhausted.If this cursor is tailable, this method will continue polling until a non-empty batch is returned from the server or the cursor is closed.
On failure, there error returned is likely one of the following:
MongoError.CommandErrorif an error occurs while fetching more results from the server.MongoError.LogicErrorif this function is called after the cursor has died.MongoError.LogicErrorif this function is called and the session associated with this cursor is inactive.DecodingErrorif an error occurs decoding the server’s response.
Declaration
Swift
public func next() -> Result<T, Error>?Return Value
A
Result<T, Error>?containing the nextTin this cursor on success, an error if one occurred, ornilif the cursor was exhausted. -
Attempt to get the next
Tfrom the cursor, returningnilif there are no results.If this cursor is tailable, this method may be called repeatedly while
isAliveis true to retrieve new data.If this cursor is a tailable await cursor, it will wait for results server side for a maximum of
maxAwaitTimeMSbefore returningnil. This option can be configured via options passed to the method that created this cursor (e.g. themaxAwaitTimeMSoption on theFindOptionspassed tofind).On failure, there error returned is likely one of the following: -
MongoError.CommandErrorif an error occurs while fetching more results from the server. -MongoError.LogicErrorif this function is called after the cursor has died. -MongoError.LogicErrorif this function is called and the session associated with this cursor is inactive. -DecodingErrorif an error occurs decoding the server’s response.Declaration
Swift
public func tryNext() -> Result<T, Error>?Return Value
A
Result<T, Error>?containing the nextTin this cursor on success, an error if one occurred, ornilif there were no results. -
Kill this cursor.
This method may be called from another thread safely even if this cursor is blocked retrieving results. This is mainly useful for freeing a thread that a cursor is blocking via a long running operation.
This method is automatically called in the
deinitofMongoCursor, so it is not necessary to call it manually.Declaration
Swift
public func kill()
View on GitHub
Install in Dash
MongoCursor Class Reference