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:
274274 :dedent:
275275 :emphasize-lines: 3
276276
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+
277306API Documentation
278307-----------------
279308
Original file line number Diff line number Diff line change @@ -93,7 +93,19 @@ object CsotExample {
9393 .timeoutMode(TimeoutMode .CURSOR_LIFETIME )
9494 // end-cursor-lifetime
9595 }
96+ {
97+ val settings = MongoClientSettings .builder
98+ .applyConnectionString(ConnectionString (" <connection string>" ))
99+ .timeout(200L , MILLISECONDS )
100+ .build
96101
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+ }
97109
98110 }
99111}
Original file line number Diff line number Diff line change @@ -93,6 +93,14 @@ constructor, as shown in the following example:
9393 :start-after: start-create-custom-bucket
9494 :end-before: end-create-custom-bucket
9595
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+
96104Upload Files
97105------------
98106
@@ -222,4 +230,4 @@ API Documentation
222230To learn more about using GridFS to store and retrieve large files,
223231see the following API documentation:
224232
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