Skip to content

Commit 38033d4

Browse files
committed
CSHARP-2253: Deprecate AutoIndexId for collection creation.
1 parent 1b77123 commit 38033d4

File tree

8 files changed

+37
-0
lines changed

8 files changed

+37
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public CreateCollectionOperation(
6969
/// <value>
7070
/// A value indicating whether an index on _id should be created automatically.
7171
/// </value>
72+
[Obsolete("AutoIndexId has been deprecated since server version 3.2.")]
7273
public bool? AutoIndexId
7374
{
7475
get { return _autoIndexId; }

src/MongoDB.Driver.Legacy/Builders/CollectionOptionsBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static IMongoCollectionOptions Null
4141
/// </summary>
4242
/// <param name="value">Whether to automatically create an index on the _id element.</param>
4343
/// <returns>The builder (so method calls can be chained).</returns>
44+
[Obsolete("AutoIndexId has been deprecated since server version 3.2.")]
4445
public static CollectionOptionsBuilder SetAutoIndexId(bool value)
4546
{
4647
return new CollectionOptionsBuilder().SetAutoIndexId(value);
@@ -163,6 +164,7 @@ public CollectionOptionsBuilder()
163164
/// </summary>
164165
/// <param name="value">Whether to automatically create an index on the _id element.</param>
165166
/// <returns>The builder (so method calls can be chained).</returns>
167+
[Obsolete("AutoIndexId has been deprecated since server version 3.2.")]
166168
public CollectionOptionsBuilder SetAutoIndexId(bool value)
167169
{
168170
_document["autoIndexId"] = value;

src/MongoDB.Driver.Legacy/MongoDatabase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ private CommandResult CreateCollection(IClientSessionHandle session, string coll
299299
}
300300
}
301301

302+
#pragma warning disable 618
302303
var operation = new CreateCollectionOperation(collectionNamespace, messageEncoderSettings)
303304
{
304305
AutoIndexId = autoIndexId,
@@ -315,6 +316,7 @@ private CommandResult CreateCollection(IClientSessionHandle session, string coll
315316
Validator = validator,
316317
WriteConcern = _settings.WriteConcern
317318
};
319+
#pragma warning restore
318320

319321
var response = ExecuteWriteOperation(session, operation);
320322
return new CommandResult(response);

src/MongoDB.Driver/CreateCollectionOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using MongoDB.Bson;
1718
using MongoDB.Bson.Serialization;
1819

@@ -50,6 +51,7 @@ public Collation Collation
5051
/// <summary>
5152
/// Gets or sets a value indicating whether to automatically create an index on the _id.
5253
/// </summary>
54+
[Obsolete("AutoIndexId has been deprecated since server version 3.2.")]
5355
public bool? AutoIndexId
5456
{
5557
get { return _autoIndexId; }
@@ -178,6 +180,7 @@ internal static CreateCollectionOptions<TDocument> CoercedFrom(CreateCollectionO
178180

179181
if (options.GetType() == typeof(CreateCollectionOptions))
180182
{
183+
#pragma warning disable 618
181184
return new CreateCollectionOptions<TDocument>
182185
{
183186
AutoIndexId = options.AutoIndexId,
@@ -193,6 +196,7 @@ internal static CreateCollectionOptions<TDocument> CoercedFrom(CreateCollectionO
193196
ValidationAction = options.ValidationAction,
194197
ValidationLevel = options.ValidationLevel
195198
};
199+
#pragma warning restore
196200
}
197201

198202
return (CreateCollectionOptions<TDocument>)options;

src/MongoDB.Driver/MongoDatabaseImpl.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ private CreateCollectionOperation CreateCreateCollectionOperation(string name, C
327327
options = options ?? new CreateCollectionOptions();
328328
var messageEncoderSettings = GetMessageEncoderSettings();
329329

330+
#pragma warning disable 618
330331
return new CreateCollectionOperation(new CollectionNamespace(_databaseNamespace, name), messageEncoderSettings)
331332
{
332333
AutoIndexId = options.AutoIndexId,
@@ -339,6 +340,7 @@ private CreateCollectionOperation CreateCreateCollectionOperation(string name, C
339340
UsePowerOf2Sizes = options.UsePowerOf2Sizes,
340341
WriteConcern = _settings.WriteConcern
341342
};
343+
#pragma warning restore
342344
}
343345

344346
private CreateCollectionOperation CreateCreateCollectionOperation<TDocument>(string name, CreateCollectionOptions<TDocument> options)
@@ -352,6 +354,7 @@ private CreateCollectionOperation CreateCreateCollectionOperation<TDocument>(str
352354
validator = options.Validator.Render(documentSerializer, serializerRegistry);
353355
}
354356

357+
#pragma warning disable 618
355358
return new CreateCollectionOperation(new CollectionNamespace(_databaseNamespace, name), messageEncoderSettings)
356359
{
357360
AutoIndexId = options.AutoIndexId,
@@ -368,6 +371,7 @@ private CreateCollectionOperation CreateCreateCollectionOperation<TDocument>(str
368371
Validator = validator,
369372
WriteConcern = _settings.WriteConcern
370373
};
374+
#pragma warning restore
371375
}
372376

373377
private CreateViewOperation CreateCreateViewOperation<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ public void AutoIndexId_get_and_set_should_work(
3838
{
3939
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings);
4040

41+
#pragma warning disable 618
4142
subject.AutoIndexId = value;
4243
var result = subject.AutoIndexId;
44+
#pragma warning restore
4345

4446
result.Should().Be(value);
4547
}
@@ -81,7 +83,9 @@ public void constructor_should_initialize_subject()
8183
subject.CollectionNamespace.Should().BeSameAs(_collectionNamespace);
8284
subject.MessageEncoderSettings.Should().BeSameAs(_messageEncoderSettings);
8385

86+
#pragma warning disable 618
8487
subject.AutoIndexId.Should().NotHaveValue();
88+
#pragma warning restore
8589
subject.Capped.Should().NotHaveValue();
8690
subject.Collation.Should().BeNull();
8791
subject.IndexOptionDefaults.Should().BeNull();
@@ -127,10 +131,12 @@ public void CreateCommand_should_return_expected_result_when_AutoIndexId_is_set(
127131
[Values(null, false, true)]
128132
bool? autoIndexId)
129133
{
134+
#pragma warning disable 618
130135
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
131136
{
132137
AutoIndexId = autoIndexId
133138
};
139+
#pragma warning restore
134140
var session = OperationTestHelper.CreateSession();
135141
var connectionDescription = OperationTestHelper.CreateConnectionDescription();
136142

@@ -472,10 +478,12 @@ public void Execute_should_create_collection_when_AutoIndexId_is_set(
472478
{
473479
RequireServer.Check().VersionLessThan("3.7.0");
474480
DropCollection();
481+
#pragma warning disable 618
475482
var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings)
476483
{
477484
AutoIndexId = autoIndexId
478485
};
486+
#pragma warning restore
479487

480488
BsonDocument info;
481489
using (var binding = CreateReadWriteBinding())

tests/MongoDB.Driver.Legacy.Tests/Builders/CollectionOptionsBuilderTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,33 @@ public class CollectionOptionsBuilderTests
2424
[Fact]
2525
public void TestSetAll()
2626
{
27+
#pragma warning disable 618
2728
var options = CollectionOptions
2829
.SetAutoIndexId(true)
2930
.SetCapped(true)
3031
.SetMaxDocuments(100)
3132
.SetMaxSize(2000);
33+
#pragma warning restore
3234
var expected = "{ 'autoIndexId' : true, 'capped' : true, 'max' : NumberLong(100), 'size' : NumberLong(2000) }".Replace("'", "\"");
3335
Assert.Equal(expected, options.ToJson());
3436
}
3537

3638
[Fact]
3739
public void TestSetAutoIndexIdFalse()
3840
{
41+
#pragma warning disable 618
3942
var options = CollectionOptions.SetAutoIndexId(false);
43+
#pragma warning restore
4044
var expected = "{ 'autoIndexId' : false }".Replace("'", "\"");
4145
Assert.Equal(expected, options.ToJson());
4246
}
4347

4448
[Fact]
4549
public void TestSetAutoIndexIdTrue()
4650
{
51+
#pragma warning disable 618
4752
var options = CollectionOptions.SetAutoIndexId(true);
53+
#pragma warning restore
4854
var expected = "{ 'autoIndexId' : true }".Replace("'", "\"");
4955
Assert.Equal(expected, options.ToJson());
5056
}

tests/MongoDB.Driver.Tests/MongoDatabaseImplTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt
7373
var storageEngine = new BsonDocument("awesome", true);
7474
var validatorDocument = BsonDocument.Parse("{ x : 1 }");
7575
var validatorDefinition = (FilterDefinition<BsonDocument>)validatorDocument;
76+
#pragma warning disable 618
7677
var options = new CreateCollectionOptions<BsonDocument>
7778
{
7879
AutoIndexId = false,
@@ -88,6 +89,7 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt
8889
ValidationLevel = DocumentValidationLevel.Off,
8990
Validator = validatorDefinition
9091
};
92+
#pragma warning restore
9193
var cancellationToken = new CancellationTokenSource().Token;
9294

9395
if (usingSession)
@@ -118,7 +120,9 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt
118120

119121
var op = call.Operation.Should().BeOfType<CreateCollectionOperation>().Subject;
120122
op.CollectionNamespace.Should().Be(new CollectionNamespace(_subject.DatabaseNamespace, name));
123+
#pragma warning disable 618
121124
op.AutoIndexId.Should().Be(options.AutoIndexId);
125+
#pragma warning restore
122126
op.Capped.Should().Be(options.Capped);
123127
op.Collation.Should().BeSameAs(options.Collation);
124128
op.IndexOptionDefaults.ToBsonDocument().Should().Be(options.IndexOptionDefaults.ToBsonDocument());
@@ -144,6 +148,7 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt
144148
var session = CreateSession(usingSession);
145149
var name = "bar";
146150
var storageEngine = new BsonDocument("awesome", true);
151+
#pragma warning disable 618
147152
var options = new CreateCollectionOptions
148153
{
149154
AutoIndexId = false,
@@ -158,6 +163,7 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt
158163
ValidationAction = DocumentValidationAction.Warn,
159164
ValidationLevel = DocumentValidationLevel.Off
160165
};
166+
#pragma warning restore
161167
var cancellationToken = new CancellationTokenSource().Token;
162168

163169
if (usingSession)
@@ -188,7 +194,9 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt
188194

189195
var op = call.Operation.Should().BeOfType<CreateCollectionOperation>().Subject;
190196
op.CollectionNamespace.Should().Be(new CollectionNamespace(_subject.DatabaseNamespace, name));
197+
#pragma warning disable 618
191198
op.AutoIndexId.Should().Be(options.AutoIndexId);
199+
#pragma warning restore
192200
op.Capped.Should().Be(options.Capped);
193201
op.Collation.Should().BeSameAs(options.Collation);
194202
op.IndexOptionDefaults.ToBsonDocument().Should().Be(options.IndexOptionDefaults.ToBsonDocument());
@@ -242,7 +250,9 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt
242250

243251
var op = call.Operation.Should().BeOfType<CreateCollectionOperation>().Subject;
244252
op.CollectionNamespace.Should().Be(new CollectionNamespace(_subject.DatabaseNamespace, name));
253+
#pragma warning disable 618
245254
op.AutoIndexId.Should().NotHaveValue();
255+
#pragma warning restore
246256
op.Capped.Should().NotHaveValue();
247257
op.IndexOptionDefaults.Should().BeNull();
248258
op.MaxDocuments.Should().NotHaveValue();

0 commit comments

Comments
 (0)