Skip to content

Commit 159d655

Browse files
committed
CSHARP-1903: Obsolete UseCursor.
1 parent 2a716e1 commit 159d655

File tree

12 files changed

+41
-5
lines changed

12 files changed

+41
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public bool RetryRequested
253253
/// <value>
254254
/// A value indicating whether the server should use a cursor to return the results.
255255
/// </value>
256+
[Obsolete("Server versions 3.6 and newer always use a cursor.")]
256257
public bool? UseCursor
257258
{
258259
get { return _useCursor; }
@@ -345,7 +346,7 @@ internal BsonDocument CreateCommand(ConnectionDescription connectionDescription,
345346

346347
if (Feature.AggregateCursorResult.IsSupported(connectionDescription.ServerVersion))
347348
{
348-
var useCursor = _useCursor.GetValueOrDefault(true) || connectionDescription.ServerVersion >= new SemanticVersion(3, 5, 0);
349+
var useCursor = _useCursor.GetValueOrDefault(true) || connectionDescription.ServerVersion >= new SemanticVersion(3, 6, 0);
349350
if (useCursor)
350351
{
351352
command["cursor"] = new BsonDocument

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescri
267267
{ "collation", () => _collation.ToBsonDocument(), _collation != null },
268268
{ "readConcern", readConcern, readConcern != null },
269269
{ "writeConcern", writeConcern, writeConcern != null },
270-
{ "cursor", new BsonDocument(), serverVersion >= new SemanticVersion(3, 5, 0) },
270+
{ "cursor", new BsonDocument(), serverVersion >= new SemanticVersion(3, 6, 0) },
271271
{ "hint", () => _hint, _hint != null },
272272
{ "comment", () => _comment, _comment != null }
273273
};

src/MongoDB.Driver.Legacy/AggregateArgs.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace MongoDB.Driver
2424
/// <summary>
2525
/// Represents the output mode for an aggregate operation.
2626
/// </summary>
27+
[Obsolete("Server versions 3.6 and newer always use a cursor.")]
2728
public enum AggregateOutputMode
2829
{
2930
/// <summary>
@@ -47,7 +48,9 @@ public class AggregateArgs
4748
private bool? _bypassDocumentValidation;
4849
private Collation _collation;
4950
private TimeSpan? _maxTime;
51+
#pragma warning disable 618
5052
private AggregateOutputMode _outputMode = AggregateOutputMode.Inline;
53+
#pragma warning restore 618
5154
private IEnumerable<BsonDocument> _pipeline;
5255

5356
// public properties
@@ -112,6 +115,7 @@ public TimeSpan? MaxTime
112115
/// <summary>
113116
/// Gets or sets the output mode.
114117
/// </summary>
118+
[Obsolete("Server versions 3.6 and newer always use a cursor.")]
115119
public AggregateOutputMode OutputMode
116120
{
117121
get { return _outputMode; }

src/MongoDB.Driver.Legacy/MongoCollection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ private IEnumerable<BsonDocument> Aggregate(IClientSessionHandle session, Aggreg
214214
MaxTime = args.MaxTime,
215215
ReadConcern = _settings.ReadConcern,
216216
RetryRequested = _server.Settings.RetryReads,
217+
#pragma warning disable 618
217218
UseCursor = args.OutputMode == AggregateOutputMode.Cursor
219+
#pragma warning restore 618
218220
};
219221
return new AggregateEnumerable(this, operation, _settings.ReadPreference);
220222
}

src/MongoDB.Driver/AggregateOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public ExpressionTranslationOptions TranslationOptions
121121
/// <summary>
122122
/// Gets or sets a value indicating whether to use a cursor.
123123
/// </summary>
124+
[Obsolete("Server versions 3.6 and newer always use a cursor.")]
124125
public bool? UseCursor
125126
{
126127
get { return _useCursor; }

src/MongoDB.Driver/MongoCollectionImpl.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,9 @@ private AggregateOperation<TResult> CreateAggregateOperation<TResult>(RenderedPi
725725
MaxTime = options.MaxTime,
726726
ReadConcern = _settings.ReadConcern,
727727
RetryRequested = _database.Client.Settings.RetryReads,
728+
#pragma warning disable 618
728729
UseCursor = options.UseCursor
730+
#pragma warning restore 618
729731
};
730732
}
731733

src/MongoDB.Driver/MongoDatabaseImpl.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ private AggregateOperation<TResult> CreateAggregateOperation<TResult>(RenderedPi
470470
MaxTime = options.MaxTime,
471471
ReadConcern = _settings.ReadConcern,
472472
RetryRequested = _client.Settings.RetryReads,
473+
#pragma warning disable 618
473474
UseCursor = options.UseCursor
475+
#pragma warning restore 618
474476
};
475477
}
476478

tests/MongoDB.Driver.Core.Tests/Core/Operations/AggregateOperationTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public void Constructor_with_database_should_create_a_valid_instance()
5151
subject.MaxAwaitTime.Should().NotHaveValue();
5252
subject.MaxTime.Should().NotHaveValue();
5353
subject.ReadConcern.IsServerDefault.Should().BeTrue();
54+
#pragma warning disable 618
5455
subject.UseCursor.Should().NotHaveValue();
56+
#pragma warning restore 618
5557
subject.RetryRequested.Should().BeFalse();
5658
}
5759

@@ -108,7 +110,9 @@ public void Constructor_with_collection_should_create_a_valid_instance()
108110
subject.MaxAwaitTime.Should().NotHaveValue();
109111
subject.MaxTime.Should().NotHaveValue();
110112
subject.ReadConcern.IsServerDefault.Should().BeTrue();
113+
#pragma warning disable 618
111114
subject.UseCursor.Should().NotHaveValue();
115+
#pragma warning restore 618
112116
subject.RetryRequested.Should().BeFalse();
113117
}
114118

@@ -276,8 +280,10 @@ public void UseCursor_get_and_set_should_work()
276280
{
277281
var subject = new AggregateOperation<BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings);
278282

283+
#pragma warning disable 618
279284
subject.UseCursor = true;
280285
var result = subject.UseCursor;
286+
#pragma warning restore 618
281287

282288
result.Should().BeTrue();
283289
}
@@ -575,7 +581,9 @@ public void CreateCommand_should_return_the_expected_result_when_UseCursor_is_se
575581
{
576582
var subject = new AggregateOperation<BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings)
577583
{
584+
#pragma warning disable 618
578585
UseCursor = useCursor
586+
#pragma warning restore 618
579587
};
580588
var serverVersion = Feature.AggregateCursorResult.SupportedOrNotSupportedVersion(useServerVersionSupportingAggregateCursorResult);
581589

@@ -901,7 +909,9 @@ public void Execute_should_return_expected_result_when_UseCursor_is_set(
901909
EnsureTestData();
902910
var subject = new AggregateOperation<BsonDocument>(_collectionNamespace, __pipeline, __resultSerializer, _messageEncoderSettings)
903911
{
912+
#pragma warning disable 618
904913
UseCursor = useCursor
914+
#pragma warning restore 618
905915
};
906916

907917
var cursor = ExecuteOperation(subject, async);

tests/MongoDB.Driver.Core.Tests/Core/Operations/AggregateToCollectionOperationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public void CreateCommand_should_return_expected_result_when_BypassDocumentValid
303303
{ "aggregate", _collectionNamespace.CollectionName },
304304
{ "pipeline", new BsonArray(__pipeline) },
305305
{ "bypassDocumentValidation", () => bypassDocumentValidation.Value, bypassDocumentValidation != null && Feature.BypassDocumentValidation.IsSupported(serverVersion) },
306-
{ "cursor", new BsonDocument(), serverVersion >= new SemanticVersion(3, 5, 0) }
306+
{ "cursor", new BsonDocument(), serverVersion >= new SemanticVersion(3, 6, 0) }
307307
};
308308
result.Should().Be(expectedResult);
309309
}

tests/MongoDB.Driver.Legacy.Tests/MongoCollectionTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ public void TestAggregateCursor()
124124
{
125125
new BsonDocument("$group", new BsonDocument { { "_id", "$x" }, { "count", new BsonDocument("$sum", 1) } })
126126
},
127+
#pragma warning disable 618
127128
OutputMode = AggregateOutputMode.Cursor,
129+
#pragma warning disable 618
128130
BatchSize = 1
129131
});
130132
var results = query.ToList();

0 commit comments

Comments
 (0)