@@ -4,10 +4,9 @@ import com.mongodb.ClientSessionOptions
4
4
import com.mongodb.ConnectionString
5
5
import com.mongodb.MongoClientSettings
6
6
import com.mongodb.TransactionOptions
7
- import com.mongodb.client.MongoClient
8
- import com.mongodb.client.MongoClients
9
7
import com.mongodb.client.cursor.TimeoutMode
10
8
import com.mongodb.client.model.Filters
9
+ import com.mongodb.kotlin.client.MongoClient
11
10
import org.bson.Document
12
11
import java.util.concurrent.TimeUnit
13
12
@@ -19,14 +18,14 @@ class CsotExample {
19
18
.timeout(200L , TimeUnit .MILLISECONDS )
20
19
.build()
21
20
22
- val client = MongoClients .create(settings)
21
+ val client = MongoClient .create(settings)
23
22
// end-mongoclientsettings
24
23
}
25
24
26
25
private fun connectionString () {
27
26
// start-string
28
27
val uri = " <connection string>/?timeoutMS=200"
29
- val client = MongoClients .create(uri)
28
+ val client = MongoClient .create(uri)
30
29
// end-string
31
30
}
32
31
@@ -37,9 +36,9 @@ class CsotExample {
37
36
.timeout(200L , TimeUnit .MILLISECONDS )
38
37
.build()
39
38
40
- MongoClients .create(settings).use { mongoClient ->
39
+ MongoClient .create(settings).use { mongoClient ->
41
40
val database = mongoClient.getDatabase(" db" )
42
- val collection = database.getCollection(" people" )
41
+ val collection = database.getCollection< Document > (" people" )
43
42
collection.insertOne(Document (" name" , " Francine Loews" ))
44
43
}
45
44
// end-operation-timeout
@@ -52,10 +51,10 @@ class CsotExample {
52
51
.timeout(200L , TimeUnit .MILLISECONDS )
53
52
.build()
54
53
55
- MongoClients .create(settings).use { mongoClient ->
54
+ MongoClient .create(settings).use { mongoClient ->
56
55
val database = mongoClient.getDatabase(" db" )
57
56
val collection = database
58
- .getCollection(" people" )
57
+ .getCollection< Document > (" people" )
59
58
.withTimeout(300L , TimeUnit .MILLISECONDS )
60
59
}
61
60
// end-override
@@ -65,10 +64,10 @@ class CsotExample {
65
64
val settings = MongoClientSettings .builder()
66
65
.applyConnectionString(ConnectionString (" <connection string>" ))
67
66
.build()
68
- MongoClients .create(settings).use { mongoClient ->
67
+ MongoClient .create(settings).use { mongoClient ->
69
68
val collection = mongoClient
70
69
.getDatabase(" db" )
71
- .getCollection(" people" )
70
+ .getCollection< Document > (" people" )
72
71
73
72
// start-session-timeout
74
73
val opts = ClientSessionOptions .builder()
@@ -93,10 +92,10 @@ class CsotExample {
93
92
.timeout(200L , TimeUnit .MILLISECONDS )
94
93
.build()
95
94
96
- MongoClients .create(settings).use { mongoClient ->
95
+ MongoClient .create(settings).use { mongoClient ->
97
96
val collection = mongoClient
98
97
.getDatabase(" db" )
99
- .getCollection(" people" )
98
+ .getCollection< Document > (" people" )
100
99
101
100
// start-cursor-lifetime
102
101
val cursorWithLifetimeTimeout = collection
0 commit comments