Skip to content

Commit 63b9ef8

Browse files
committed
CSHARP-2839: Add support for AllowDiskUse with Find.
1 parent f11ded8 commit 63b9ef8

File tree

21 files changed

+300
-2
lines changed

21 files changed

+300
-2
lines changed

src/MongoDB.Driver.Core/Core/Operations/FindCommandOperation.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class FindCommandOperation<TDocument> : IReadOperation<IAsyncCursor<TDocu
4545
#endregion
4646

4747
// fields
48+
private bool? _allowDiskUse;
4849
private bool? _allowPartialResults;
4950
private int? _batchSize;
5051
private Collation _collation;
@@ -93,6 +94,18 @@ public FindCommandOperation(
9394
}
9495

9596
// properties
97+
/// <summary>
98+
/// Gets or sets a value indicating whether the server is allowed to write to disk while executing the Find operation.
99+
/// </summary>
100+
/// <value>
101+
/// <c>true</c> if the server is allowed to write to disk while executing the Find operation; otherwise, <c>false</c>.
102+
/// </value>
103+
public bool? AllowDiskUse
104+
{
105+
get { return _allowDiskUse; }
106+
set { _allowDiskUse = value; }
107+
}
108+
96109
/// <summary>
97110
/// Gets or sets a value indicating whether the server is allowed to return partial results if any shards are unavailable.
98111
/// </summary>
@@ -459,6 +472,7 @@ internal BsonDocument CreateCommand(ConnectionDescription connectionDescription,
459472
{ "oplogReplay", () => _oplogReplay.Value, _oplogReplay.HasValue },
460473
{ "noCursorTimeout", () => _noCursorTimeout.Value, _noCursorTimeout.HasValue },
461474
{ "awaitData", true, _cursorType == CursorType.TailableAwait },
475+
{ "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue },
462476
{ "allowPartialResults", () => _allowPartialResults.Value, _allowPartialResults.HasValue && isShardRouter },
463477
{ "collation", () => _collation.ToBsonDocument(), _collation != null },
464478
{ "readConcern", readConcern, readConcern != null }

src/MongoDB.Driver.Core/Core/Operations/FindOperation.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace MongoDB.Driver.Core.Operations
3131
public class FindOperation<TDocument> : IReadOperation<IAsyncCursor<TDocument>>, IExecutableInRetryableReadContext<IAsyncCursor<TDocument>>
3232
{
3333
// fields
34+
private bool? _allowDiskUse;
3435
private bool? _allowPartialResults;
3536
private int? _batchSize;
3637
private Collation _collation;
@@ -80,6 +81,18 @@ public FindOperation(
8081
}
8182

8283
// properties
84+
/// <summary>
85+
/// Gets or sets a value indicating whether the server is allowed to write to disk while executing the Find operation.
86+
/// </summary>
87+
/// <value>
88+
/// <c>true</c> if the server is allowed to write to disk while executing the Find operation; otherwise, <c>false</c>.
89+
/// </value>
90+
public bool? AllowDiskUse
91+
{
92+
get { return _allowDiskUse; }
93+
set { _allowDiskUse = value; }
94+
}
95+
8396
/// <summary>
8497
/// Gets or sets a value indicating whether the server is allowed to return partial results if any shards are unavailable.
8598
/// </summary>
@@ -511,6 +524,7 @@ internal FindCommandOperation<TDocument> CreateFindCommandOperation()
511524
_resultSerializer,
512525
_messageEncoderSettings)
513526
{
527+
AllowDiskUse = _allowDiskUse,
514528
AllowPartialResults = _allowPartialResults,
515529
BatchSize = _batchSize,
516530
Collation = _collation,
@@ -559,6 +573,7 @@ internal FindOpcodeOperation<TDocument> CreateFindOpcodeOperation()
559573
_resultSerializer,
560574
_messageEncoderSettings)
561575
{
576+
// note: FindOpcodeOperation does not support AllowDiskUse
562577
AllowPartialResults = _allowPartialResults,
563578
BatchSize = _batchSize,
564579
Comment = _comment,

src/MongoDB.Driver.GridFS/GridFSBucket.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ private FindOperation<GridFSFileInfo<TFileId>> CreateFindOperation(FilterDefinit
637637
_fileInfoSerializer,
638638
messageEncoderSettings)
639639
{
640+
AllowDiskUse = options.AllowDiskUse,
640641
BatchSize = options.BatchSize,
641642
Filter = renderedFilter,
642643
Limit = options.Limit,

src/MongoDB.Driver.GridFS/GridFSBucketCompat.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ private GridFSFindOptions<ObjectId> WrapFindOptions(GridFSFindOptions options)
253253
var wrappedSort = renderedSort == null ? null : new BsonDocumentSortDefinition<GridFSFileInfo<ObjectId>>(renderedSort);
254254
return new GridFSFindOptions<ObjectId>
255255
{
256+
AllowDiskUse = options.AllowDiskUse,
256257
BatchSize = options.BatchSize,
257258
Limit = options.Limit,
258259
MaxTime = options.MaxTime,

src/MongoDB.Driver.GridFS/GridFSFindOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace MongoDB.Driver.GridFS
2525
public class GridFSFindOptions<TFileId>
2626
{
2727
// fields
28+
private bool? _allowDiskUse;
2829
private int? _batchSize;
2930
private int? _limit;
3031
private TimeSpan? _maxTime;
@@ -33,6 +34,15 @@ public class GridFSFindOptions<TFileId>
3334
private SortDefinition<GridFSFileInfo<TFileId>> _sort;
3435

3536
// properties
37+
/// <summary>
38+
/// Gets or sets a value indicating whether the server is allowed to write to disk while executing the Find operation.
39+
/// </summary>
40+
public bool? AllowDiskUse
41+
{
42+
get { return _allowDiskUse; }
43+
set { _allowDiskUse = value; }
44+
}
45+
3646
/// <summary>
3747
/// Gets or sets the batch size.
3848
/// </summary>

src/MongoDB.Driver/FindFluent.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public override IFindFluent<TDocument, TNewProjection> Project<TNewProjection>(P
123123
{
124124
var newOptions = new FindOptions<TDocument, TNewProjection>
125125
{
126+
AllowDiskUse = _options.AllowDiskUse,
126127
AllowPartialResults = _options.AllowPartialResults,
127128
BatchSize = _options.BatchSize,
128129
Collation = _options.Collation,

src/MongoDB.Driver/FindOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace MongoDB.Driver
2525
public abstract class FindOptionsBase
2626
{
2727
// fields
28+
private bool? _allowDiskUse;
2829
private bool? _allowPartialResults;
2930
private int? _batchSize;
3031
private Collation _collation;
@@ -51,6 +52,15 @@ public FindOptionsBase()
5152
}
5253

5354
// properties
55+
/// <summary>
56+
/// Gets or sets a value indicating whether the server is allowed to write to disk while executing the Find operation.
57+
/// </summary>
58+
public bool? AllowDiskUse
59+
{
60+
get { return _allowDiskUse; }
61+
set { _allowDiskUse = value; }
62+
}
63+
5464
/// <summary>
5565
/// Gets or sets a value indicating whether to allow partial results when some shards are unavailable.
5666
/// </summary>

src/MongoDB.Driver/IMongoCollectionExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,7 @@ private static IFindFluent<TDocument, TDocument> FindHelper<TDocument>(IClientSe
838838
{
839839
genericOptions = new FindOptions<TDocument>
840840
{
841+
AllowDiskUse = options.AllowDiskUse,
841842
AllowPartialResults = options.AllowPartialResults,
842843
BatchSize = options.BatchSize,
843844
Collation = options.Collation,

src/MongoDB.Driver/MongoCollectionImpl.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ private FindOperation<TProjection> CreateFindOperation<TProjection>(FilterDefini
966966
renderedProjection.ProjectionSerializer,
967967
_messageEncoderSettings)
968968
{
969+
AllowDiskUse = options.AllowDiskUse,
969970
AllowPartialResults = options.AllowPartialResults,
970971
BatchSize = options.BatchSize,
971972
Collation = options.Collation,

tests/MongoDB.Driver.Core.TestHelpers/JsonDrivenTests/CommandStartedEventAsserter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private void AssertCommandAspect(BsonDocument actualCommand, string name, BsonVa
110110
{
111111
switch (name)
112112
{
113+
case "allowDiskUse":
113114
case "autocommit":
114115
case "readConcern":
115116
case "recoveryToken":

0 commit comments

Comments
 (0)