Classes

The following classes are available globally.

  • A MongoDB change stream.

    See more

    Declaration

    Swift

    public class ChangeStream<T> : CursorProtocol where T : Decodable, T : Encodable
  • A MongoDB client session. This class represents a logical session used for ordering sequential operations.

    To create a client session, use startSession or withSession on a MongoClient.

    If causalConsistency is not set to false when starting a session, read and write operations that use the session will be provided causal consistency guarantees depending on the read and write concerns used. Using “majority” read and write preferences will provide the full set of guarantees. See https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#sessions for more details.

    e.g.

       let opts = CollectionOptions(readConcern: ReadConcern(.majority), writeConcern: try WriteConcern(w: .majority))
       let collection = database.collection("mycoll", options: opts)
       try client.withSession { session in
           try collection.insertOne(["x": 1], session: session)
           try collection.find(["x": 1], session: session)
       }
    

    To disable causal consistency, set causalConsistency to false in the ClientSessionOptions passed in to either withSession or startSession.

    See more

    Declaration

    Swift

    public final class ClientSession
  • A MongoDB Client providing a synchronous API.

    See more

    Declaration

    Swift

    public class MongoClient
    extension MongoClient: Equatable
  • 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.

    See more

    Declaration

    Swift

    public class MongoCursor<T> : CursorProtocol where T : Decodable, T : Encodable