Server

public final class Server

A server object is the core of MongoKitten as it’s used to communicate to the server. You can select a Database by subscripting an instance of this Server with a String.

  • The logging instance

    Do not reply on this. LogKitten is an alpha product and exclusively used by MongoKitten for exposing debugging information

    Declaration

    Swift

    public var logger: Logger
  • Undocumented

    Declaration

    Swift

    public final class Server
  • Handles errors within cursors

    Declaration

    Swift

    public var cursorErrorHandler: ((Error)->()) = { doc in
  • The default cursor strategy to use server-wide

    Declaration

    Swift

    public var cursorStrategy: CursorStrategy = .intelligent(bufferChunks: 3)
  • Maximum amount of simultanious operations per connection

    Declaration

    Swift

    public var maxActionsPerConnection = 10
  • The default write concern at the Server level

    Declaration

    Swift

    public var writeConcern: WriteConcern?
  • The default read concern at the Server level

    Declaration

    Swift

    public var readConcern: ReadConcern?
  • The default Collation for collections at the Server level.

    Declaration

    Swift

    public var collation: Collation? = nil
  • The server’s BuildInfo

    Do not access from the initialization process!

    Declaration

    Swift

    public private(set) var buildInfo: BuildInfo! = nil
  • Sets up the Server to connect to MongoDB.

    Throws

    When we can’t connect automatically, when the scheme/host is invalid and when we can’t connect automatically

    Declaration

    Swift

    public init(_ clientSettings: ClientSettings) throws
  • Sets up the Server to connect to the specified URL. The mongodb:// scheme is required as well as the host. Optionally youc an provide ausername + password. And if no port is specified 27017 is used. You can provide an alternative TCP Driver that complies to MongoTCP. This Server doesn’t connect automatically. You need to either use the connect function yourself or specify the automatically parameter to be true.

    Throws

    When we can’t connect automatically, when the scheme/host is invalid and when we can’t connect automatically

    Declaration

    Swift

    convenience public init(_ url: String, maxConnectionsPerServer maxConnections: Int = 100, defaultTimeout: TimeInterval = 30) throws
  • Sets up the Server to connect to the specified location.Server You need to provide a host as IP address or as a hostname recognized by the client’s DNS.

    Throws

    When we can’t connect automatically, when the scheme/host is invalid and when we can’t connect automatically

    Declaration

    Swift

    convenience public init(hostname host: String, port: UInt16 = 27017, authenticatedAs authentication: MongoCredentials? = nil, maxConnectionsPerServer maxConnections: Int = 100, ssl sslSettings: SSLSettings? = nil) throws
  • Returns a Database instance referring to the database with the provided database name

    Declaration

    Swift

    public subscript(databaseName: String) -> Database

    Return Value

    A database instance for the requested database

  • Are we currently connected?

    Declaration

    Swift

    public var isConnected: Bool
  • Disconnects from the MongoDB server

    Throws

    Unable to disconnect

    Declaration

    Swift

    public func disconnect() throws
  • Provides a list of all existing databases along with basic statistics about them

    For more information: https://docs.mongodb.com/manual/reference/command/listDatabases/#dbcmd.listDatabases

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func getDatabaseInfos() throws -> Document
  • Returns all existing databases on this server. Requires access to the admin database

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func getDatabases() throws -> [Database]

    Return Value

    All databases

  • Copies a database either from one mongod instance to the current mongod instance or within the current mongod

    For more information: https://docs.mongodb.com/manual/reference/command/copydb/#dbcmd.copydb

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func copy(database db: String, to otherDatabase: String, as user: (user: String, nonce: String, password: String)? = nil, at remoteHost: String? = nil, slaveOk: Bool? = nil) throws
  • Clones a database from the specified MongoDB Connection URI

    For more information: https://docs.mongodb.com/manual/reference/command/clone/#dbcmd.clone

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func clone(from url: String) throws
  • Shuts down the MongoDB server

    For more information: https://docs.mongodb.com/manual/reference/command/shutdown/#dbcmd.shutdown

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func shutdown(forced force: Bool? = nil) throws
  • Flushes all pending writes serverside

    For more information: https://docs.mongodb.com/manual/reference/command/fsync/#dbcmd.fsync

    Declaration

    Swift

    public func fsync(async asynchronously: Bool? = nil, blocking block: Bool? = nil) throws
  • Gets the info from the user

    For more information: https://docs.mongodb.com/manual/reference/command/usersInfo/#dbcmd.usersInfo

    Throws

    When unable to send the request/receive the response, the authenticated user doesn’t have sufficient permissions or an error occurred

    Declaration

    Swift

    public func getUserInfo(forUserNamed user: String, inDatabase database: Database? = nil, showCredentials: Bool? = nil, showPrivileges: Bool? = nil) throws -> Document

    Return Value

    The user’s information (plus optionally the credentials and privileges)

  • Undocumented

    Declaration

    Swift

    public final class Server
  • A textual representation of this Server

    Declaration

    Swift

    public var description: String
  • Iterates over all databases

    Declaration

    Swift

    public func makeIterator() -> AnyIterator<Database>