File tree Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Expand file tree Collapse file tree 3 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,35 @@ inherited timeout:
274
274
:dedent:
275
275
:emphasize-lines: 3
276
276
277
+ .. _scala-csot-gridfs:
278
+
279
+ GridFS
280
+ ------
281
+
282
+ You can set a timeout option for :ref:`GridFS <scala-gridfs>`
283
+ operations when instantiating a ``GridFSBucket`` by using the
284
+ ``withTimeout()`` method. This timeout applies to all operations
285
+ performed on the bucket, such as uploading and downloading data. If you
286
+ do not set a timeout, the ``GridFSBucket`` instance inherits the timeout
287
+ setting from the ``MongoDatabase`` it is created with.
288
+
289
+ The following code demonstrates how to set a timeout when instantiating
290
+ a ``GridFSBucket``:
291
+
292
+ .. literalinclude:: /includes/connect/CsotExample.scala
293
+ :language: scala
294
+ :start-after: start-gridfsbucket-timeout
295
+ :end-before: end-gridfsbucket-timeout
296
+ :dedent:
297
+
298
+ .. important:: Observable Timeout Support
299
+
300
+ When you call the ``uploadFromObservable()`` method on a ``GridFSBucket``
301
+ that has an operation timeout, timeout breaches might occur because
302
+ the ``Observable`` class lacks inherent read timeout support. This might
303
+ extend the operation beyond the specified timeout limit, causing a
304
+ timeout exception.
305
+
277
306
API Documentation
278
307
-----------------
279
308
Original file line number Diff line number Diff line change @@ -93,7 +93,19 @@ object CsotExample {
93
93
.timeoutMode(TimeoutMode .CURSOR_LIFETIME )
94
94
// end-cursor-lifetime
95
95
}
96
+ {
97
+ val settings = MongoClientSettings .builder
98
+ .applyConnectionString(ConnectionString (" <connection string>" ))
99
+ .timeout(200L , MILLISECONDS )
100
+ .build
96
101
102
+ val mongoClient = MongoClient (settings)
103
+ val database = mongoClient.getDatabase(" db" )
104
+
105
+ // start-gridfsbucket-timeout
106
+ val gridFSBucket = GridFSBucket (database).withTimeout(200L , MILLISECONDS )
107
+ // end-gridfsbucket-timeout
108
+ }
97
109
98
110
}
99
111
}
Original file line number Diff line number Diff line change @@ -93,6 +93,14 @@ constructor, as shown in the following example:
93
93
:start-after: start-create-custom-bucket
94
94
:end-before: end-create-custom-bucket
95
95
96
+ .. tip:: Timeout Setting
97
+
98
+ You can use the client-side operation timeout (CSOT) setting to limit
99
+ the amount of time in which the server can finish GridFS operations
100
+ on your bucket. To learn more about using this setting with GridFS, see the
101
+ :ref:`scala-csot-gridfs` section of the Limit Server Execution Time
102
+ guide.
103
+
96
104
Upload Files
97
105
------------
98
106
@@ -222,4 +230,4 @@ API Documentation
222
230
To learn more about using GridFS to store and retrieve large files,
223
231
see the following API documentation:
224
232
225
- - `GridFSBucket <{+driver-api+}/gridfs/GridFSBucket$.html>`__
233
+ - `GridFSBucket <{+driver-api+}/gridfs/GridFSBucket$.html>`__
You can’t perform that action at this time.
0 commit comments