ChangeStream
public class ChangeStream<T> : CursorProtocol where T : Decodable, T : Encodable
A MongoDB change stream.
-
The
ResumeTokenassociated with the most recent event seen by the change stream.Declaration
Swift
public var resumeToken: ResumeToken? { get } -
Indicates whether this change stream has the potential to return more data.
This change stream will be dead after
nextreturnsnil, but it may still be alive aftertryNextreturnsnil.After either of
nextortryNextreturn a non-DecodingErrorerror, this change stream will be dead. It may still be alive after either returns aDecodingError, however.Declaration
Swift
public func isAlive() -> Bool -
Get the next
Tfrom this change stream.This method will block until an event is returned from the server, an error occurred, or the change stream is killed. Each attempt to retrieve results will wait server-side for a maximum of
maxAwaitTimeMS(specified on theChangeStreamOptionspassed to the method that created this change stream) before making another request.A thread from the pool will be occupied by this method until it returns, so performance degradation is possible if the number of polling change streams is too close to the total number of threads in the thread pool. To configure the total number of threads in the pool, set the
MongoClientOptions.threadPoolSizeoption on client creation.If the result contains an error, it 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 change stream has died. -MongoError.LogicErrorif this function is called and the session associated with this change stream 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 change stream or an error if one occurred, ornilif the change stream is exhausted. This method will block until one of those conditions is met, potentially after multiple requests to the server. -
Attempt to get the next
Tfrom this change stream, returningnilif there are no results.The change stream will wait server-side for a maximum of
maxAwaitTimeMS(specified on theChangeStreamOptionspassed to the method that created this change stream) before returningnil.This method may be called repeatedly while
isAliveis true to retrieve new data.Declaration
Swift
public func tryNext() -> Result<T, Error>?Return Value
A
Result<T, Error>?containing the nextTin this change stream, an error if one occurred, ornilif there was no data.If the result is an error, it 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 change stream has died.MongoError.LogicErrorif this function is called and the session associated with this change stream is inactive.
DecodingErrorif an error occurs decoding the server’s response.
-
Kill this change stream.
This method may be called from another thread safely even if this change stream is blocked retrieving results. This is mainly useful for freeing a thread that the change stream is blocking with a long running operation.
This method is automatically called in the
deinitofChangeStream, so it is not necessary to call it manually.This method will have no effect if the change stream is already dead.
Declaration
Swift
public func kill()
View on GitHub
Install in Dash
ChangeStream Class Reference