@@ -10,7 +10,7 @@ private func causalConsistency() throws {
1010 let elg = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
1111 let client1 = try MongoClient ( using: elg)
1212 defer {
13- client1. syncShutdown ( )
13+ try ? client1. syncClose ( )
1414 try ? elg. syncShutdownGracefully ( )
1515 }
1616
@@ -40,7 +40,7 @@ private func causalConsistency() throws {
4040 s2. advanceClusterTime ( to: s1. clusterTime!)
4141 s2. advanceOperationTime ( to: s1. operationTime!)
4242
43- dbOptions. readPreference = ReadPreference ( . secondary)
43+ dbOptions. readPreference = . secondary
4444 let items2 = client2. db ( " test " , options: dbOptions) . collection ( " items " )
4545
4646 return items2. find ( [ " end " : . null] , session: s2) . flatMap { cursor in
@@ -147,80 +147,3 @@ private func changeStreams() throws {
147147 // End Changestream Example 4
148148 }
149149}
150-
151- /// Examples used for the MongoDB documentation on Transactions.
152- /// - SeeAlso: https://docs.mongodb.com/manual/core/transactions/
153- private func transactions( ) throws {
154- let elg = MultiThreadedEventLoopGroup ( numberOfThreads: 1 )
155- let client = try MongoClient ( using: elg)
156- let session = client. startSession ( )
157-
158- defer {
159- client. syncShutdown ( )
160- cleanupMongoSwift ( )
161- try ? elg. syncShutdownGracefully ( )
162- }
163-
164- do {
165- // Start Transactions Example 1
166- let db = client. db ( " test " )
167- let srcColl = db. collection ( " src " )
168- let destColl = db. collection ( " coll " )
169- let docToMove : Document = [ " hello " : " world " ]
170-
171- session. startTransaction ( ) . flatMap { _ in
172- srcColl. deleteOne ( docToMove, session: session)
173- } . flatMap { _ in
174- destColl. insertOne ( docToMove, session: session)
175- } . flatMap { _ in
176- session. commitTransaction ( )
177- } . whenFailure { _ in
178- session. abortTransaction ( )
179- // handle error
180- }
181- // End Transactions Example 1
182- }
183-
184- do {
185- // Start Transactions Example 2
186- let txnOpts = TransactionOptions (
187- maxCommitTimeMS: 30 ,
188- readConcern: ReadConcern ( . local) ,
189- readPreference: . primaryPreferred,
190- writeConcern: try WriteConcern ( w: . majority)
191- )
192-
193- session. startTransaction ( options: txnOpts) . flatMap { _ in
194- // do something
195- } . flatMap { _ in
196- session. commitTransaction ( )
197- } . whenFailure { _ in
198- session. abortTransaction ( )
199- // handle error
200- }
201- // End Transactions Example 2
202- }
203-
204- do {
205- // Start Transactions Example 3
206- let txnOpts = TransactionOptions (
207- maxCommitTimeMS: 30 ,
208- readConcern: ReadConcern ( . local) ,
209- readPreference: . primaryPreferred,
210- writeConcern: try WriteConcern ( w: . majority)
211- )
212-
213- let client = try MongoClient ( using: elg)
214- let session = client. startSession ( options: ClientSessionOptions ( defaultTransactionOptions: txnOpts) )
215-
216- session. startTransaction ( ) . flatMap { _ in
217- // do something
218- } . flatMap { _ in
219- session. commitTransaction ( )
220- } . whenFailure { _ in
221- session. abortTransaction ( )
222- // handle error
223- }
224- // End Transactions Example 3
225- }
226- }
0 commit comments