Skip to content

Commit bbcda37

Browse files
committed
CSHARP-2213: Deprecate MaxScan query option.
1 parent 8c5ba62 commit bbcda37

File tree

8 files changed

+33
-2
lines changed

8 files changed

+33
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ public TimeSpan? MaxAwaitTime
241241
/// <value>
242242
/// The max scan.
243243
/// </value>
244+
[Obsolete("MaxScan was deprecated in server version 4.0.")]
244245
public int? MaxScan
245246
{
246247
get { return _maxScan; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public BsonDocument Max
206206
/// <value>
207207
/// The max scan.
208208
/// </value>
209+
[Obsolete("MaxScan was deprecated in server version 4.0.")]
209210
public int? MaxScan
210211
{
211212
get { return _maxScan; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ public TimeSpan? MaxAwaitTime
228228
/// <value>
229229
/// The max scan.
230230
/// </value>
231+
[Obsolete("MaxScan was deprecated in server version 4.0.")]
231232
public int? MaxScan
232233
{
233234
get { return _maxScan; }

src/MongoDB.Driver.Legacy/MongoCursor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ public virtual MongoCursor SetMaxAwaitTime(TimeSpan? value)
574574
/// </summary>
575575
/// <param name="maxScan">The maximum number of documents to scan.</param>
576576
/// <returns>The cursor (so you can chain method calls to it).</returns>
577+
[Obsolete("MaxScan was deprecated in server version 4.0.")]
577578
public virtual MongoCursor SetMaxScan(int maxScan)
578579
{
579580
if (_isFrozen) { ThrowFrozen(); }
@@ -985,6 +986,7 @@ private IEnumerator<TDocument> GetEnumerator(IClientSessionHandle session)
985986
/// </summary>
986987
/// <param name="maxScan">The maximum number of documents to scan.</param>
987988
/// <returns>The cursor (so you can chain method calls to it).</returns>
989+
[Obsolete("MaxScan was deprecated in server version 4.0.")]
988990
public new virtual MongoCursor<TDocument> SetMaxScan(int maxScan)
989991
{
990992
return (MongoCursor<TDocument>)base.SetMaxScan(maxScan);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ public void constructor_should_initialize_instance()
123123
subject.Limit.Should().NotHaveValue();
124124
subject.Max.Should().BeNull();
125125
subject.MaxAwaitTime.Should().NotHaveValue();
126+
#pragma warning disable 618
126127
subject.MaxScan.Should().NotHaveValue();
128+
#pragma warning restore
127129
subject.MaxTime.Should().NotHaveValue();
128130
subject.Min.Should().BeNull();
129131
subject.NoCursorTimeout.Should().NotHaveValue();
@@ -417,10 +419,12 @@ public void CreateCommand_should_return_expected_result_when_MaxScan_is_set(
417419
[Values(null, 1, 2)]
418420
int? maxScan)
419421
{
422+
#pragma warning disable 618
420423
var subject = new FindCommandOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings)
421424
{
422425
MaxScan = maxScan
423426
};
427+
#pragma warning restore
424428

425429
var connectionDescription = OperationTestHelper.CreateConnectionDescription();
426430
var session = OperationTestHelper.CreateSession();
@@ -1020,8 +1024,10 @@ public void MaxScan_get_and_set_should_work(
10201024
{
10211025
var subject = new FindCommandOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
10221026

1027+
#pragma warning disable 618
10231028
subject.MaxScan = value;
10241029
var result = subject.MaxScan;
1030+
#pragma warning restore
10251031

10261032
result.Should().Be(value);
10271033
}
@@ -1034,7 +1040,9 @@ public void MaxScan_should_throw_when_value_is_invalid(
10341040
{
10351041
var subject = new FindCommandOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
10361042

1043+
#pragma warning disable 618
10371044
var exception = Record.Exception(() => { subject.MaxScan = value; });
1045+
#pragma warning restore
10381046

10391047
var argumentOutOfRangeException = exception.Should().BeOfType<ArgumentOutOfRangeException>().Subject;
10401048
argumentOutOfRangeException.ParamName.Should().Be("value");

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public void constructor_should_initialize_instance()
121121
subject.Hint.Should().BeNull();
122122
subject.Limit.Should().NotHaveValue();
123123
subject.Max.Should().BeNull();
124+
#pragma warning disable 618
124125
subject.MaxScan.Should().NotHaveValue();
126+
#pragma warning restore
125127
subject.MaxTime.Should().NotHaveValue();
126128
subject.Modifiers.Should().BeNull();
127129
subject.Min.Should().BeNull();
@@ -445,8 +447,10 @@ public void MaxScan_get_and_set_should_work(
445447
{
446448
var subject = new FindOpcodeOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
447449

450+
#pragma warning disable 618
448451
subject.MaxScan = value;
449452
var result = subject.MaxScan;
453+
#pragma warning restore
450454

451455
result.Should().Be(value);
452456
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ public void constructor_should_initialize_instance()
138138
subject.Limit.Should().NotHaveValue();
139139
subject.Max.Should().BeNull();
140140
subject.MaxAwaitTime.Should().NotHaveValue();
141+
#pragma warning disable 618
141142
subject.MaxScan.Should().NotHaveValue();
143+
#pragma warning restore
142144
subject.MaxTime.Should().NotHaveValue();
143145
subject.Min.Should().BeNull();
144146
subject.Modifiers.Should().BeNull();
@@ -230,7 +232,9 @@ public void CreateFindCommandOperation_should_return_expected_result()
230232
result.Limit.Should().Be(subject.Limit);
231233
result.Max.Should().BeSameAs(subject.Max);
232234
result.MaxAwaitTime.Should().Be(subject.MaxAwaitTime);
235+
#pragma warning disable 618
233236
result.MaxScan.Should().Be(subject.MaxScan);
237+
#pragma warning restore
234238
result.MaxTime.Should().Be(subject.MaxTime);
235239
result.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
236240
result.Min.Should().BeSameAs(subject.Min);
@@ -274,7 +278,9 @@ public void CreateFindCommandOperation_should_return_expected_result_when_modifi
274278
result.Comment.Should().Be(subject.Modifiers["$comment"].AsString);
275279
result.Hint.Should().Be(subject.Modifiers["$hint"]);
276280
result.Max.Should().Be(subject.Modifiers["$max"].AsBsonDocument);
281+
#pragma warning disable 618
277282
result.MaxScan.Should().Be(subject.Modifiers["$maxScan"].AsInt32);
283+
#pragma warning restore
278284
result.MaxTime.Should().Be(TimeSpan.FromMilliseconds(subject.Modifiers["$maxTimeMS"].AsInt32));
279285
result.Min.Should().Be(subject.Modifiers["$min"].AsBsonDocument);
280286
result.ReturnKey.Should().Be(subject.Modifiers["$returnKey"].ToBoolean());
@@ -328,7 +334,9 @@ public void CreateFindOpcodeOperation_should_return_expected_result()
328334
result.Hint.Should().Be(subject.Hint);
329335
result.Limit.Should().Be(subject.Limit);
330336
result.Max.Should().Be(subject.Max);
337+
#pragma warning disable 618
331338
result.MaxScan.Should().Be(subject.MaxScan);
339+
#pragma warning restore
332340
result.MaxTime.Should().Be(subject.MaxTime);
333341
result.MessageEncoderSettings.Should().BeSameAs(subject.MessageEncoderSettings);
334342
result.Min.Should().Be(subject.Min);
@@ -705,8 +713,10 @@ public void MaxScan_get_and_set_should_work(
705713
{
706714
var subject = new FindOperation<BsonDocument>(_collectionNamespace, BsonDocumentSerializer.Instance, _messageEncoderSettings);
707715

716+
#pragma warning disable 618
708717
subject.MaxScan = value;
709718
var result = subject.MaxScan;
719+
#pragma warning restore
710720

711721
result.Should().Be(value);
712722
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,17 @@ public void TestBulkWriteUnordered()
407407
Assert.Equal(0, _collection.Count());
408408
}
409409

410-
#pragma warning disable 618
411410
[Fact]
412411
public void TestConstructorArgumentChecking()
413412
{
414413
var settings = new MongoCollectionSettings();
414+
#pragma warning disable 618
415415
Assert.Throws<ArgumentNullException>(() => { new MongoCollection<BsonDocument>(null, "name", settings); });
416416
Assert.Throws<ArgumentNullException>(() => { new MongoCollection<BsonDocument>(_database, null, settings); });
417417
Assert.Throws<ArgumentNullException>(() => { new MongoCollection<BsonDocument>(_database, "name", null); });
418418
Assert.Throws<ArgumentOutOfRangeException>(() => { new MongoCollection<BsonDocument>(_database, "", settings); });
419+
#pragma warning restore
419420
}
420-
#pragma warning disable
421421

422422
[Fact]
423423
public void TestCountZero()
@@ -577,7 +577,9 @@ public void TestCreateCollectionSetAutoIndexId(
577577
RequireServer.Check().VersionLessThan("3.7.0");
578578
var collection = _database.GetCollection("cappedcollection");
579579
collection.Drop();
580+
#pragma warning disable 618
580581
var options = CollectionOptions.SetAutoIndexId(autoIndexId);
582+
#pragma warning restore
581583
var expectedIndexCount = autoIndexId ? 1 : 0;
582584

583585
_database.CreateCollection(collection.Name, options);
@@ -1568,7 +1570,9 @@ public void TestFindWithMaxScan()
15681570
var docs = Enumerable.Range(0, 10).Select(x => new BsonDocument("_id", x));
15691571
_collection.InsertBatch(docs);
15701572

1573+
#pragma warning disable 618
15711574
var results = _collection.FindAll().SetMaxScan(4).ToList();
1575+
#pragma warning restore
15721576
Assert.Equal(4, results.Count);
15731577
}
15741578

0 commit comments

Comments
 (0)