Skip to content

Commit 4ae3b6d

Browse files
authored
minor: add sync Atlas connection examples (#686)
1 parent 258a560 commit 4ae3b6d

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Examples/Atlas/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ let package = Package(
1111
.package(url: "https://github.com/apple/swift-nio", .upToNextMajor(from: "2.0.0"))
1212
],
1313
targets: [
14-
.target(name: "AtlasExamples", dependencies: ["MongoSwift", "NIO"]),
14+
.target(name: "AtlasExamples", dependencies: ["MongoSwift", "MongoSwiftSync", "NIO"]),
1515
]
1616
)

Examples/Atlas/Sources/AtlasExamples/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import MongoSwift
33
import NIO
44

55
/// Atlas connection string examples
6+
/// Please include the above imports in the snippets.
67

78
func scramExample() throws {
89
// START SCRAM EXAMPLE HERE
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Foundation
2+
import MongoSwiftSync
3+
4+
/// Atlas connection string examples
5+
/// Please include the above imports in the snippet.
6+
7+
func syncScramExample() throws {
8+
// START SCRAM EXAMPLE HERE
9+
let client = try MongoClient(
10+
"mongodb+srv://<user>:<password>@<host>/<dbname>?retryWrites=true&w=majority"
11+
)
12+
defer {
13+
cleanupMongoSwift()
14+
}
15+
16+
let db = client.db("library")
17+
let collection = db.collection("books")
18+
// do something with collection
19+
// END SCRAM EXAMPLE HERE
20+
}
21+
22+
func syncX509Example() throws {
23+
// START x509 EXAMPLE HERE
24+
let options = MongoClientOptions(
25+
credential: MongoCredential(mechanism: .mongodbX509),
26+
tlsCAFile: URL(string: "/path/to/cert"),
27+
tlsCertificateKeyFile: URL(string: "/path/to/cert")
28+
)
29+
let client = try MongoClient(
30+
"mongodb+srv://<host>/<dbname>?retryWrites=true&w=majority",
31+
options: options
32+
)
33+
defer {
34+
cleanupMongoSwift()
35+
}
36+
37+
let db = client.db("library")
38+
let collection = db.collection("books")
39+
// do something with collection
40+
// END x509 EXAMPLE HERE
41+
}

0 commit comments

Comments
 (0)