@@ -6,7 +6,7 @@ import MongoSwift
66/// Examples used for the MongoDB documentation on Causal Consistency.
77/// - SeeAlso: https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#examples
88private func causalConsistency( ) throws {
9- let client1 = try MongoClient ( )
9+ let client1 = try SyncMongoClient ( )
1010
1111 // Start Causal Consistency Example 1
1212 let s1 = try client1. startSession ( options: ClientSessionOptions ( causalConsistency: true ) )
@@ -17,14 +17,14 @@ private func causalConsistency() throws {
1717 )
1818 let items = client1. db ( " test " , options: dbOptions) . collection ( " items " )
1919 try items. updateOne (
20- filter: [ " sku " : " 111 " , " end " : BSONNull ( ) ] ,
21- update: [ " $set " : [ " end " : currentDate] as Document ] ,
20+ filter: [ " sku " : " 111 " , " end " : . null ] ,
21+ update: [ " $set " : [ " end " : . datetime ( currentDate) ] ] ,
2222 session: s1
2323 )
24- try items. insertOne ( [ " sku " : " nuts-111 " , " name " : " Pecans " , " start " : currentDate] , session: s1)
24+ try items. insertOne ( [ " sku " : " nuts-111 " , " name " : " Pecans " , " start " : . datetime ( currentDate) ] , session: s1)
2525 // End Causal Consistency Example 1
2626
27- let client2 = try MongoClient ( )
27+ let client2 = try SyncMongoClient ( )
2828
2929 // Start Causal Consistency Example 2
3030 try client2. withSession ( options: ClientSessionOptions ( causalConsistency: true ) ) { s2 in
@@ -34,7 +34,7 @@ private func causalConsistency() throws {
3434
3535 dbOptions. readPreference = ReadPreference ( . secondary)
3636 let items2 = client2. db ( " test " , options: dbOptions) . collection ( " items " )
37- for item in try items2. find ( [ " end " : BSONNull ( ) ] , session: s2) {
37+ for item in try items2. find ( [ " end " : . null ] , session: s2) {
3838 print ( item)
3939 }
4040 }
@@ -44,7 +44,7 @@ private func causalConsistency() throws {
4444/// Examples used for the MongoDB documentation on Change Streams.
4545/// - SeeAlso: https://docs.mongodb.com/manual/changeStreams/
4646private func changeStreams( ) throws {
47- let client = try MongoClient ( )
47+ let client = try SyncMongoClient ( )
4848 let db = client. db ( " example " )
4949
5050 // The following examples assume that you have connected to a MongoDB replica set and have
@@ -81,8 +81,8 @@ private func changeStreams() throws {
8181 do {
8282 // Start Changestream Example 4
8383 let pipeline : [ Document ] = [
84- [ " $match " : [ " fullDocument.username " : " alice " ] as Document ] ,
85- [ " $addFields " : [ " newField " : " this is an added field! " ] as Document ]
84+ [ " $match " : [ " fullDocument.username " : " alice " ] ] ,
85+ [ " $addFields " : [ " newField " : " this is an added field! " ] ]
8686 ]
8787 let inventory = db. collection ( " inventory " )
8888 let cursor = try inventory. watch ( pipeline, withEventType: Document . self)
0 commit comments