Sessions & Transactions
-
A MongoDB client session. This class represents a logical session used for ordering sequential operations.
To create a client session, use
startSessionorwithSessionon aMongoClient.If
causalConsistencyis not set tofalsewhen 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 = MongoCollectionOptions(readConcern: .majority, writeConcern: .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
causalConsistencytofalsein theClientSessionOptionspassed in to eitherwithSessionorstartSession.See moreSee also
Declaration
Swift
public final class ClientSession -
Options to use when creating a
See moreClientSession.Declaration
Swift
public struct ClientSessionOptions -
Options to use when starting a transaction.
See moreDeclaration
Swift
public struct TransactionOptions
View on GitHub
Install in Dash
Sessions & Transactions Reference