@@ -55,7 +55,7 @@ public class AggregationOptions implements ReadConcernAware, ReadPreferenceAware
55
55
private static final String MAX_TIME = "maxTimeMS" ;
56
56
private static final String HINT = "hint" ;
57
57
58
- private final boolean allowDiskUse ;
58
+ private final Optional < Boolean > allowDiskUse ;
59
59
private final boolean explain ;
60
60
private final Optional <Document > cursor ;
61
61
private final Optional <Collation > collation ;
@@ -123,10 +123,10 @@ public AggregationOptions(boolean allowDiskUse, boolean explain, @Nullable Docum
123
123
* @param hint can be {@literal null}, used to provide an index that would be forcibly used by query optimizer.
124
124
* @since 3.1
125
125
*/
126
- private AggregationOptions (boolean allowDiskUse , boolean explain , @ Nullable Document cursor ,
126
+ private AggregationOptions (@ Nullable Boolean allowDiskUse , boolean explain , @ Nullable Document cursor ,
127
127
@ Nullable Collation collation , @ Nullable String comment , @ Nullable Object hint ) {
128
128
129
- this .allowDiskUse = allowDiskUse ;
129
+ this .allowDiskUse = Optional . ofNullable ( allowDiskUse ) ;
130
130
this .explain = explain ;
131
131
this .cursor = Optional .ofNullable (cursor );
132
132
this .collation = Optional .ofNullable (collation );
@@ -159,7 +159,7 @@ public static AggregationOptions fromDocument(Document document) {
159
159
160
160
Assert .notNull (document , "Document must not be null" );
161
161
162
- boolean allowDiskUse = document .getBoolean (ALLOW_DISK_USE , false );
162
+ Boolean allowDiskUse = document .get (ALLOW_DISK_USE , Boolean . class );
163
163
boolean explain = document .getBoolean (EXPLAIN , false );
164
164
Document cursor = document .get (CURSOR , Document .class );
165
165
Collation collation = document .containsKey (COLLATION ) ? Collation .from (document .get (COLLATION , Document .class ))
@@ -185,13 +185,23 @@ public static Builder builder() {
185
185
}
186
186
187
187
/**
188
- * Enables writing to temporary files. When set to true, aggregation stages can write data to the _tmp subdirectory in
189
- * the dbPath directory.
188
+ * Enables writing to temporary files. When set to {@literal true} , aggregation stages can write data to the
189
+ * {@code _tmp} subdirectory in the {@code dbPath} directory.
190
190
*
191
- * @return {@literal true} if enabled.
191
+ * @return {@literal true} if enabled; {@literal false} otherwise (or if not set) .
192
192
*/
193
193
public boolean isAllowDiskUse () {
194
- return allowDiskUse ;
194
+ return allowDiskUse .orElse (false );
195
+ }
196
+
197
+ /**
198
+ * Return whether {@link #isAllowDiskUse} is configured.
199
+ *
200
+ * @return {@literal true} if is {@code allowDiskUse} is configured, {@literal false} otherwise.
201
+ * @since 4.2.5
202
+ */
203
+ public boolean isAllowDiskUseSet () {
204
+ return allowDiskUse .isPresent ();
195
205
}
196
206
197
207
/**
@@ -335,8 +345,8 @@ Document applyAndReturnPotentiallyChangedCommand(Document command) {
335
345
336
346
Document result = new Document (command );
337
347
338
- if (allowDiskUse && !result .containsKey (ALLOW_DISK_USE )) {
339
- result .put (ALLOW_DISK_USE , allowDiskUse );
348
+ if (isAllowDiskUseSet () && !result .containsKey (ALLOW_DISK_USE )) {
349
+ result .put (ALLOW_DISK_USE , isAllowDiskUse () );
340
350
}
341
351
342
352
if (explain && !result .containsKey (EXPLAIN )) {
@@ -370,7 +380,9 @@ Document applyAndReturnPotentiallyChangedCommand(Document command) {
370
380
public Document toDocument () {
371
381
372
382
Document document = new Document ();
373
- document .put (ALLOW_DISK_USE , allowDiskUse );
383
+ if (isAllowDiskUseSet ()) {
384
+ document .put (ALLOW_DISK_USE , isAllowDiskUse ());
385
+ }
374
386
document .put (EXPLAIN , explain );
375
387
376
388
cursor .ifPresent (val -> document .put (CURSOR , val ));
@@ -410,7 +422,7 @@ static Document createCursor(int cursorBatchSize) {
410
422
*/
411
423
public static class Builder {
412
424
413
- private boolean allowDiskUse ;
425
+ private Boolean allowDiskUse ;
414
426
private boolean explain ;
415
427
private @ Nullable Document cursor ;
416
428
private @ Nullable Collation collation ;
0 commit comments