Skip to content

Commit affba36

Browse files
committed
Update examples to use 1.0.0-rc1 APIs
1 parent 9ca6ad8 commit affba36

File tree

5 files changed

+6
-83
lines changed

5 files changed

+6
-83
lines changed

Examples/Docs/Sources/AsyncExamples/main.swift

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
}

Examples/Docs/Sources/SyncExamples/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private func causalConsistency() throws {
3232
s2.advanceClusterTime(to: s1.clusterTime!)
3333
s2.advanceOperationTime(to: s1.operationTime!)
3434

35-
dbOptions.readPreference = ReadPreference(.secondary)
35+
dbOptions.readPreference = .secondary
3636
let items2 = client2.db("test", options: dbOptions).collection("items")
3737
for item in try items2.find(["end": .null], session: s2) {
3838
print(item)

Examples/KituraExample/Sources/KituraExample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 4)
1313
let mongoClient = try MongoClient(using: eventLoopGroup)
1414

1515
defer {
16-
mongoClient.syncShutdown()
16+
try? mongoClient.syncClose()
1717
cleanupMongoSwift()
1818
try? eventLoopGroup.syncShutdownGracefully()
1919
}

Examples/PerfectExample/Sources/PerfectExample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let mongoClient = try MongoClient(using: elg)
1616

1717
defer {
1818
// Close the client and clean up global driver resources.
19-
mongoClient.syncShutdown()
19+
try? mongoClient.syncClose()
2020
cleanupMongoSwift()
2121
// Shut down the EventLoopGroup.
2222
try? elg.syncShutdownGracefully()

Examples/VaporExample/Sources/VaporExample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let app = Application(env)
88

99
defer {
1010
// shut down the client and clean up the driver's global resources.
11-
app.mongoClient.syncShutdown()
11+
try? app.mongoClient.syncClose()
1212
cleanupMongoSwift()
1313
app.shutdown()
1414
}

0 commit comments

Comments
 (0)