@@ -6,71 +6,69 @@ import org.bson.Document
6
6
// SCRAM Authentication
7
7
// start-default-cred-string
8
8
val mongoClient =
9
- MongoClient .create(" mongodb+srv ://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>" )
9
+ MongoClient .create(" mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=<authenticationDb>" )
10
10
// end-default-cred-string
11
11
12
12
// start-default-mongo-cred
13
13
val credential = MongoCredential .createCredential(
14
14
" <db_username>" , " <authenticationDb>" , " <db_password>" .toCharArray()
15
15
)
16
16
17
+ val credential = MongoCredential .createCredential(
18
+ " <db_username>" , " <authenticationDb>" , " <db_password>" .toCharArray()
19
+ )
17
20
val settings = MongoClientSettings .builder()
18
- .applyToClusterSettings { builder: ClusterSettings .Builder ->
19
- builder.srvHost(" <hostname>" )
20
- }
21
- .credential(credential)
22
- .applyToSslSettings { builder ->
23
- builder.enabled(true )
24
- }
25
- .build()
21
+ .applyToClusterSettings { builder: ClusterSettings .Builder ->
22
+ builder.hosts(
23
+ listOf (ServerAddress (" <hostname>" , " <port>" ))
24
+ )
25
+ }
26
+ .credential(credential)
27
+ .build()
26
28
27
29
val mongoClient = MongoClient .create(settings)
28
30
// end-default-mongo-cred
29
31
30
32
// start-scramsha256-cred-string
31
33
val mongoClient =
32
- MongoClient .create(" mongodb+srv ://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-256" )
34
+ MongoClient .create(" mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-256" )
33
35
// end-scramsha256-cred-string
34
36
35
37
// start-scramsha256-mongo-cred
36
38
val credential = MongoCredential .createScramSha256Credential(
37
- " <db_username>" , " <authenticationDb>" , " <db_password>" .toCharArray()
38
- )
39
-
39
+ " <db_username>" , " <authenticationDb>" , " <db_password>" .toCharArray()
40
+ )
40
41
val settings = MongoClientSettings .builder()
41
- .applyToClusterSettings { builder: ClusterSettings .Builder ->
42
- builder.srvHost(" <hostname>" )
43
- }
44
- .applyToSslSettings { builder ->
45
- builder.enabled(true )
46
- }
47
- .credential(credential)
48
- .build()
42
+ .applyToClusterSettings { builder: ClusterSettings .Builder ->
43
+ builder.hosts(
44
+ listOf (ServerAddress (" <hostname>" , " <port>" ))
45
+ )
46
+ }
47
+ .credential(credential)
48
+ .build()
49
49
50
50
val mongoClient = MongoClient .create(settings)
51
51
// end-scramsha256-mongo-cred
52
52
53
53
// start-scramsha1-cred-string
54
54
val mongoClient =
55
- MongoClient .create(" mongodb+srv ://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-1" )
55
+ MongoClient .create(" mongodb://<db_username>:<db_password>@<hostname>:<port>/?authSource=admin&authMechanism=SCRAM-SHA-1" )
56
56
// end-scramsha1-cred-string
57
57
58
58
// start-scramsha1-mongo-cred
59
59
val credential = MongoCredential .createScramSha1Credential(
60
- " <db_username>" , " <authenticationDb>" , " <db_password>" .toCharArray()
61
- )
62
-
60
+ " <db_username>" , " <authenticationDb>" , " <db_password>" .toCharArray()
61
+ )
63
62
val settings = MongoClientSettings .builder()
64
- .applyToClusterSettings { builder: ClusterSettings .Builder ->
65
- builder.srvHost(" <hostname>" )
66
- }
67
- .applyToSslSettings { builder ->
68
- builder.enabled(true )
69
- }
70
- .credential(credential)
71
- .build()
72
-
73
- val mongoClient = MongoClient .create(settings)
63
+ .applyToClusterSettings { builder: ClusterSettings .Builder ->
64
+ builder.hosts(
65
+ listOf (ServerAddress (" <hostname>" , " <port>" ))
66
+ )
67
+ }
68
+ .credential(credential)
69
+ .build()
70
+
71
+ val mongoClient = MongoClient .create(settings)
74
72
// end-scramsha1-mongo-cred
75
73
76
74
// AWS Authentication
0 commit comments