EventLoopBoundMongoClient
public struct EventLoopBoundMongoClient
A wrapper around a MongoClient
that will return EventLoopFuture
s on the specified EventLoop
.
-
The
EventLoop
thisEventLoopBoundMongoClient
will be bound to.Declaration
Swift
public let eventLoop: EventLoop
-
Retrieves a list of databases in this client’s MongoDB deployment. The returned future will be on the
EventLoop
specified on thisEventLoopBoundMongoClient
.Declaration
Swift
public func listDatabases( _ filter: BSONDocument? = nil, options: ListDatabasesOptions? = nil, session: ClientSession? = nil ) -> EventLoopFuture<[DatabaseSpecification]>
Parameters
filter
Optional
BSONDocument
specifying a filter that the listed databases must pass. This filter can be based on the “name”, “sizeOnDisk”, “empty”, or “shards” fields of the output.options
Optional
ListDatabasesOptions
specifying options for listing databases.session
Optional
ClientSession
to use when executing this command.Return Value
An
EventLoopFuture<[DatabaseSpecification]>
on theEventLoop
specified on thisEventLoopBoundMongoClient
. On success, the future contains an array of the specifications of databases matching the provided criteria.If the future fails, the error is likely one of the following:
MongoError.LogicError
if the provided session is inactive.MongoError.LogicError
if this client has already been closed.EncodingError
if an error is encountered while encoding the options to BSON.MongoError.CommandError
if options.authorizedDatabases is false and the user does not have listDatabases permissions.
-
Gets the names of databases in this client’s MongoDB deployment. The returned future will be on the
EventLoop
specified on thisEventLoopBoundMongoClient
.Declaration
Swift
public func listDatabaseNames( _ filter: BSONDocument? = nil, options: ListDatabasesOptions? = nil, session: ClientSession? = nil ) -> EventLoopFuture<[String]>
Parameters
filter
Optional
BSONDocument
specifying a filter on the names of the returned databases.options
Optional
ListDatabasesOptions
specifying options for listing databases.session
Optional
ClientSession
to use when executing this commandReturn Value
An
EventLoopFuture<[String]>
on theEventLoop
specified on thisEventLoopBoundMongoClient
. On success, the future contains an array of names of databases that match the provided filter.If the future fails, the error is likely one of the following:
MongoError.LogicError
if the provided session is inactive.MongoError.LogicError
if this client has already been closed.MongoError.CommandError
if options.authorizedDatabases is false and the user does not have listDatabases permissions.
-
Gets a
MongoDatabase
instance for the given database name that will returnEventLoopFuture
s on thisEventLoopBoundMongoClient
‘sEventLoop
. If an option is not specified in the optionalMongoDatabaseOptions
param, the database will inherit the value from thisEventLoopBoundMongoClient
’s underlyingMongoClient
or the default if the client’s option is not set. To override an option inherited from the client (e.g. a read concern) with the default value, it must be explicitly specified in the options param (e.g. ReadConcern.serverDefault, not nil).Declaration
Swift
public func db(_ name: String, options: MongoDatabaseOptions? = nil) -> MongoDatabase
Parameters
name
the name of the database to retrieve
options
Optional
MongoDatabaseOptions
to use for the retrieved databaseReturn Value
A
MongoDatabase
that is bound to thisEventLoopBoundMongoClient
‘sEventLoop
. -
Starts a
ChangeStream
on thisEventLoopBoundMongoClient
. The returned future will be on theEventLoop
specified on thisEventLoopBoundMongoClient
. Allows the client to observe all changes in a cluster - excluding system collections and the “config”, “local”, and “admin” databases.Warning
If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the change stream is dead before it leaves scope, invoke
ChangeStream.kill(...)
on it.See also
SeeAlso:
Note
Supported in MongoDB version 4.0+ only.
Declaration
Swift
public func watch( _ pipeline: [BSONDocument] = [], options: ChangeStreamOptions? = nil, session: ClientSession? = nil ) -> EventLoopFuture<ChangeStream<ChangeStreamEvent<BSONDocument>>>
Parameters
pipeline
An array of aggregation pipeline stages to apply to the events returned by the change stream.
options
An optional
ChangeStreamOptions
to use when constructing the change stream.session
An optional
ClientSession
to use with this change stream.Return Value
An
EventLoopFuture<ChangeStream>
on thisEventLoopBoundMongoClient
‘sEventLoop
. On success, contains aChangeStream
watching all collections in this deployment. TheChangeStream
’s methods will return futures on theEventLoop
specified on thisEventLoopBoundMongoClient
.If the future fails, the error is likely one of the following:
MongoError.CommandError
if an error occurs on the server while creating the change stream.MongoError.InvalidArgumentError
if the options passed formed an invalid combination.MongoError.InvalidArgumentError
if the_id
field is projected out of the change stream documents by the pipeline.
-
Starts a
ChangeStream
on thisEventLoopBoundMongoClient
. The returned future will be on theEventLoop
specified on thisEventLoopBoundMongoClient
. Allows the client to observe all changes in a cluster - excluding system collections and the “config”, “local”, and “admin” databases. Associates the specifiedCodable
typeT
with thefullDocument
field in theChangeStreamEvent
s emitted by the returnedChangeStream
.Warning
If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the change stream is dead before it leaves scope, invoke
ChangeStream.kill(...)
on it.See also
SeeAlso:
Note
Supported in MongoDB version 4.0+ only.
Declaration
Swift
public func watch<FullDocType: Codable>( _ pipeline: [BSONDocument] = [], options: ChangeStreamOptions? = nil, session: ClientSession? = nil, withFullDocumentType _: FullDocType.Type ) -> EventLoopFuture<ChangeStream<ChangeStreamEvent<FullDocType>>>
Parameters
pipeline
An array of aggregation pipeline stages to apply to the events returned by the change stream.
options
An optional
ChangeStreamOptions
to use when constructing the change stream.session
An optional
ClientSession
to use with this change stream.withFullDocumentType
The type that the
fullDocument
field of the emittedChangeStreamEvent
s will be decoded to.Return Value
An
EventLoopFuture<ChangeStream>
on thisEventLoopBoundMongoClient
‘sEventLoop
. On success, contains aChangeStream
watching all collections in this deployment. TheChangeStream
’s methods will return futures on theEventLoop
specified on thisEventLoopBoundMongoClient
.If the future fails, the error is likely one of the following:
MongoError.CommandError
if an error occurs on the server while creating the change stream.MongoError.InvalidArgumentError
if the options passed formed an invalid combination.MongoError.InvalidArgumentError
if the_id
field is projected out of the change stream documents by the pipeline.
-
Starts a
ChangeStream
on thisEventLoopBoundMongoClient
. The returned future will be on theEventLoop
specified on thisEventLoopBoundMongoClient
. Allows the client to observe all changes in a cluster - excluding system collections and the “config”, “local”, and “admin” databases. Associates the specifiedCodable
typeT
with the returnedChangeStream
.Warning
If the returned change stream is alive when it goes out of scope, it will leak resources. To ensure the change stream is dead before it leaves scope, invoke
ChangeStream.kill(...)
on it.See also
SeeAlso:
Note
Supported in MongoDB version 4.0+ only.
Declaration
Swift
public func watch<EventType: Codable>( _ pipeline: [BSONDocument] = [], options: ChangeStreamOptions? = nil, session: ClientSession? = nil, withEventType _: EventType.Type ) -> EventLoopFuture<ChangeStream<EventType>>
Parameters
pipeline
An array of aggregation pipeline stages to apply to the events returned by the change stream.
options
An optional
ChangeStreamOptions
to use when constructing the change stream.session
An optional
ClientSession
to use with this change stream.withEventType
The type that the entire change stream response will be decoded to and that will be returned when iterating through the change stream.
Return Value
An
EventLoopFuture<ChangeStream>
on thisEventLoopBoundMongoClient
‘sEventLoop
. On success, contains aChangeStream
watching all collections in this deployment. TheChangeStream
’s methods will return futures on theEventLoop
specified on thisEventLoopBoundMongoClient
.If the future fails, the error is likely one of the following:
MongoError.CommandError
if an error occurs on the server while creating the change stream.MongoError.InvalidArgumentError
if the options passed formed an invalid combination.MongoError.InvalidArgumentError
if the_id
field is projected out of the change stream documents by the pipeline.
-
Starts a new
ClientSession
with the provided options. TheClientSession
will be bound to theEventLoop
specified on thisEventLoopBoundMongoClient
. When you are done using this session, you must callClientSession.end()
on it.Declaration
Swift
public func startSession(options: ClientSessionOptions? = nil) -> ClientSession
Parameters
options
The options to use when starting this session.
Return Value
A
ClientSession
that is bound to thisEventLoopBoundMongoClient
‘sEventLoop
. -
Starts a new
ClientSession
with the provided options and passes it to the provided closure. The returned future will be on theEventLoop
specified on thisEventLoopBoundMongoClient
. The session is only valid within the body of the closure and will be ended after the body completes.Declaration
Swift
public func withSession<T>( options: ClientSessionOptions? = nil, _ sessionBody: (ClientSession) throws -> EventLoopFuture<T> ) -> EventLoopFuture<T>
Parameters
options
Options to use when creating the session.
sessionBody
A closure which takes in a
ClientSession
and returns anEventLoopFuture<T>
.Return Value
An
EventLoopFuture<T>
, the return value of the user-provided closure, on thisEventLoopBoundMongoClient
‘sEventLoop
.If the future fails, the error is likely one of the following:
CompatibilityError
if the deployment does not support sessions.MongoError.LogicError
if this client has already been closed.