diff --git a/Docs/reference/content/reference/driver/admin.md b/Docs/reference/content/reference/driver/admin.md index f2369aefba6..7966ffb561e 100644 --- a/Docs/reference/content/reference/driver/admin.md +++ b/Docs/reference/content/reference/driver/admin.md @@ -64,7 +64,7 @@ using (var cursor = await client.ListDatabaseAsync()) ## Collections -These operations exists on the [`IMongoDatabase`]({{< apiref "T_MongoDB_Driver_IMongoDatabase" >}}) interface. +These operations exist on the [`IMongoDatabase`]({{< apiref "T_MongoDB_Driver_IMongoDatabase" >}}) interface. ### Getting a collection @@ -88,7 +88,7 @@ var options = new CreateCollectionOptions { Capped = true, MaxSize = 10000 -}); +}; ``` ```csharp // creates a capped collection named "foo" with a maximum size of 10,000 bytes @@ -99,6 +99,19 @@ db.CreateCollection("foo", options); await db.CreateCollectionAsync("foo", options); ``` +### Creating a clustered collection + +*New in MongoDB 5.3.* [Clustered collections](https://www.mongodb.com/docs/upcoming/core/clustered-collections/) are collections created +with a clustered index. Documents in a clustered collection are ordered by the clustered index key value. To create a clustered collection: + +```csharp +var options = new CreateCollectionOptions +{ + ClusteredIndex = new ClusteredIndexOptions() +}; +db.CreateCollection("product", options); +``` + ### Dropping a collection Use the [`DropCollection`]({{< apiref "M_MongoDB_Driver_IMongoDatabase_DropCollection" >}}) or [`DropCollectionAsync`]({{< apiref "M_MongoDB_Driver_IMongoDatabase_DropCollectionAsync" >}}) methods. @@ -272,4 +285,4 @@ using (var cursor = await collection.Indexes.ListAsync()) var list = await cursor.ToListAsync(); // do something with the list... } -``` \ No newline at end of file +``` diff --git a/src/MongoDB.Driver.Core/Core/Misc/Feature.cs b/src/MongoDB.Driver.Core/Core/Misc/Feature.cs index 2b374377304..4ebdd23ebd5 100644 --- a/src/MongoDB.Driver.Core/Core/Misc/Feature.cs +++ b/src/MongoDB.Driver.Core/Core/Misc/Feature.cs @@ -1,4 +1,4 @@ -/* Copyright 2016-present MongoDB Inc. +/* Copyright 2016-present MongoDB Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,7 @@ public class Feature private static readonly Feature __changeStreamPostBatchResumeToken = new Feature("ChangeStreamPostBatchResumeToken", WireVersion.Server40); private static readonly Feature __changeStreamPrePostImages = new Feature("ChangeStreamPrePostImages", WireVersion.Server60); private static readonly Feature __clientSideEncryption = new Feature("ClientSideEncryption", WireVersion.Server42); + private static readonly Feature __clusteredIndexes = new Feature("ClusteredIndexes", WireVersion.Server53); private static readonly Feature __collation = new Feature("Collation", WireVersion.Server34); private static readonly Feature __commandMessage = new Feature("CommandMessage", WireVersion.Server36); private static readonly Feature __commandsThatWriteAcceptWriteConcern = new Feature("CommandsThatWriteAcceptWriteConcern", WireVersion.Server34); @@ -266,6 +267,12 @@ public class Feature /// public static Feature ClientSideEncryption => __clientSideEncryption; + + /// + /// Gets the clustered indexes feature. + /// + public static Feature ClusteredIndexes => __clusteredIndexes; + /// /// Gets the collation feature. /// diff --git a/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs b/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs index 069228fd961..fb071c4d772 100644 --- a/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs +++ b/src/MongoDB.Driver.Core/Core/Operations/CreateCollectionOperation.cs @@ -69,6 +69,7 @@ CreateCollectionOperation CreateInnerCollectionOperation(string collectionName) // fields private bool? _autoIndexId; private bool? _capped; + private BsonDocument _clusteredIndex; private Collation _collation; private readonly CollectionNamespace _collectionNamespace; private BsonValue _comment; @@ -324,6 +325,18 @@ public WriteConcern WriteConcern set { _writeConcern = value; } } + /// + /// Gets or sets the clustered index definition. + /// + /// + /// The clustered index definition. + /// + public BsonDocument ClusteredIndex + { + get => _clusteredIndex; + set => _clusteredIndex = value; + } + // methods internal BsonDocument CreateCommand(ICoreSessionHandle session) { @@ -332,6 +345,7 @@ internal BsonDocument CreateCommand(ICoreSessionHandle session) return new BsonDocument { { "create", _collectionNamespace.CollectionName }, + { "clusteredIndex", _clusteredIndex, _clusteredIndex != null }, { "capped", () => _capped.Value, _capped.HasValue }, { "autoIndexId", () => _autoIndexId.Value, _autoIndexId.HasValue }, { "size", () => _maxSize.Value, _maxSize.HasValue }, diff --git a/src/MongoDB.Driver/ClusteredIndexOptions.cs b/src/MongoDB.Driver/ClusteredIndexOptions.cs new file mode 100644 index 00000000000..5a42ed87a97 --- /dev/null +++ b/src/MongoDB.Driver/ClusteredIndexOptions.cs @@ -0,0 +1,75 @@ +/* Copyright 2010-present MongoDB Inc. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +using MongoDB.Bson; +using MongoDB.Bson.Serialization; + +namespace MongoDB.Driver +{ + /// + /// Options for creating a clustered index. + /// + public class ClusteredIndexOptions + { + private IndexKeysDefinition _key; + private string _name; + private bool _unique; + + /// + /// Initializes a new instance of the class. + /// + public ClusteredIndexOptions() + { + _key = new BsonDocument { { "_id", 1 } }; + _unique = true; + } + + /// + /// Gets or sets the index key, which must currently be {_id: 1}. + /// + public IndexKeysDefinition Key + { + get => _key; + set => _key = value; + } + + /// + /// Gets or sets the index name. + /// + public string Name + { + get => _name; + set => _name = value; + } + + /// + /// Gets or sets whether the index entries must be unique, which currently must be true. + /// + public bool Unique + { + get => _unique; + set => _unique = value; + } + + internal BsonDocument Render(IBsonSerializer documentSerializer, IBsonSerializerRegistry serializerRegistry) + { + return new BsonDocument { + { "key", _key.Render(documentSerializer, serializerRegistry) }, + { "unique", _unique }, + { "name", _name, _name != null } + }; + } + } +} diff --git a/src/MongoDB.Driver/CreateCollectionOptions.cs b/src/MongoDB.Driver/CreateCollectionOptions.cs index 7a732a9132d..e0eb544c643 100644 --- a/src/MongoDB.Driver/CreateCollectionOptions.cs +++ b/src/MongoDB.Driver/CreateCollectionOptions.cs @@ -237,10 +237,20 @@ internal static CreateCollectionOptions CoercedFrom(CreateCollectionO #endregion // private fields + private ClusteredIndexOptions _clusteredIndex; private IBsonSerializer _documentSerializer; private FilterDefinition _validator; // public properties + /// + /// Gets or sets the . + /// + public ClusteredIndexOptions ClusteredIndex + { + get { return _clusteredIndex; } + set { _clusteredIndex = value; } + } + /// /// Gets or sets the document serializer. /// diff --git a/src/MongoDB.Driver/CreateIndexModel.cs b/src/MongoDB.Driver/CreateIndexModel.cs index 8a022cc5de7..04d916ed40a 100644 --- a/src/MongoDB.Driver/CreateIndexModel.cs +++ b/src/MongoDB.Driver/CreateIndexModel.cs @@ -13,13 +13,7 @@ * limitations under the License. */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using MongoDB.Driver.Core.Misc; -using MongoDB.Driver.Core.Operations; namespace MongoDB.Driver { diff --git a/src/MongoDB.Driver/MongoDatabaseImpl.cs b/src/MongoDB.Driver/MongoDatabaseImpl.cs index 99b0e2bc632..e4b83689f82 100644 --- a/src/MongoDB.Driver/MongoDatabaseImpl.cs +++ b/src/MongoDB.Driver/MongoDatabaseImpl.cs @@ -644,13 +644,11 @@ private Task CreateCollectionHelperAsync(IClientSessionHandle session private IWriteOperation CreateCreateCollectionOperation(string name, CreateCollectionOptions options) { - BsonDocument validator = null; - if (options.Validator != null) - { - var serializerRegistry = options.SerializerRegistry ?? BsonSerializer.SerializerRegistry; - var documentSerializer = options.DocumentSerializer ?? serializerRegistry.GetSerializer(); - validator = options.Validator.Render(documentSerializer, serializerRegistry, _linqProvider); - } + var serializerRegistry = options.SerializerRegistry ?? BsonSerializer.SerializerRegistry; + var documentSerializer = options.DocumentSerializer ?? serializerRegistry.GetSerializer(); + + var clusteredIndex = options.ClusteredIndex?.Render(documentSerializer, serializerRegistry); + var validator = options.Validator?.Render(documentSerializer, serializerRegistry, _linqProvider); var collectionNamespace = new CollectionNamespace(_databaseNamespace, name); @@ -667,6 +665,7 @@ private IWriteOperation CreateCreateCollectionOperation cco.AutoIndexId = options.AutoIndexId; #pragma warning restore CS0618 // Type or member is obsolete cco.Capped = options.Capped; + cco.ClusteredIndex = clusteredIndex; cco.Collation = options.Collation; cco.ExpireAfter = options.ExpireAfter; cco.IndexOptionDefaults = options.IndexOptionDefaults?.ToBsonDocument(); diff --git a/tests/MongoDB.Driver.Core.Tests/Core/Operations/CreateCollectionOperationTests.cs b/tests/MongoDB.Driver.Core.Tests/Core/Operations/CreateCollectionOperationTests.cs index b6ce794cc06..17d868ae646 100644 --- a/tests/MongoDB.Driver.Core.Tests/Core/Operations/CreateCollectionOperationTests.cs +++ b/tests/MongoDB.Driver.Core.Tests/Core/Operations/CreateCollectionOperationTests.cs @@ -87,6 +87,7 @@ public void constructor_should_initialize_subject() subject.AutoIndexId.Should().NotHaveValue(); #pragma warning restore subject.Capped.Should().NotHaveValue(); + subject.ClusteredIndex.Should().BeNull(); subject.Collation.Should().BeNull(); subject.EncryptedFields.Should().BeNull(); subject.IndexOptionDefaults.Should().BeNull(); @@ -171,6 +172,28 @@ public void CreateCommand_should_return_expected_result_when_Capped_is_set( result.Should().Be(expectedResult); } + [Theory] + [ParameterAttributeData] + public void CreateCommand_should_return_expected_result_when_ClusteredIndex_is_set( + [Values(null, "{ key : { _id : 1 }, unique : true }", "{ key : { _id : 1 }, unique : true, name: 'clustered index name' }")] + string clusteredIndex) + { + var subject = new CreateCollectionOperation(_collectionNamespace, _messageEncoderSettings) + { + ClusteredIndex = clusteredIndex != null ? BsonDocument.Parse(clusteredIndex) : null + }; + var session = OperationTestHelper.CreateSession(); + + var result = subject.CreateCommand(session); + + var expectedResult = new BsonDocument + { + { "create", _collectionNamespace.CollectionName }, + { "clusteredIndex", () => BsonDocument.Parse(clusteredIndex), clusteredIndex != null } + }; + result.Should().Be(expectedResult); + } + [Theory] [ParameterAttributeData] public void CreateCommand_should_return_expected_result_when_Collation_is_set( diff --git a/tests/MongoDB.Driver.TestConsoleApplication/Program.cs b/tests/MongoDB.Driver.TestConsoleApplication/Program.cs index f0eaf68e7fe..0b3cd227892 100644 --- a/tests/MongoDB.Driver.TestConsoleApplication/Program.cs +++ b/tests/MongoDB.Driver.TestConsoleApplication/Program.cs @@ -15,6 +15,7 @@ using System; using System.IO; +using MongoDB.Bson; using MongoDB.Driver.Core.Configuration; using MongoDB.Driver.Core.Events.Diagnostics; diff --git a/tests/MongoDB.Driver.Tests/MongoDatabaseImplTests.cs b/tests/MongoDB.Driver.Tests/MongoDatabaseImplTests.cs index bcb6566779f..355360d85b7 100644 --- a/tests/MongoDB.Driver.Tests/MongoDatabaseImplTests.cs +++ b/tests/MongoDB.Driver.Tests/MongoDatabaseImplTests.cs @@ -25,6 +25,7 @@ using MongoDB.Bson.TestHelpers.XunitExtensions; using MongoDB.Driver.Core.Bindings; using MongoDB.Driver.Core.Clusters; +using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.Operations; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Tests; @@ -381,8 +382,14 @@ public void AggregateToCollection_should_throw_when_last_stage_is_not_an_output_ [ParameterAttributeData] public void CreateCollection_should_execute_a_CreateCollectionOperation_when_options_is_generic( [Values(false, true)] bool usingSession, + [Values(false, true)] bool clustered, [Values(false, true)] bool async) { + if (clustered) + { + RequireServer.Check().Supports(Feature.ClusteredIndexes); + } + var writeConcern = new WriteConcern(1); var subject = _subject.WithWriteConcern(writeConcern); var session = CreateSession(usingSession); @@ -395,6 +402,7 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt { AutoIndexId = false, Capped = true, + ClusteredIndex = clustered ? new ClusteredIndexOptions() : null, Collation = new Collation("en_US"), IndexOptionDefaults = new IndexOptionDefaults { StorageEngine = new BsonDocument("x", 1) }, MaxDocuments = 10, @@ -441,6 +449,14 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt op.AutoIndexId.Should().Be(options.AutoIndexId); #pragma warning restore op.Capped.Should().Be(options.Capped); + if (clustered) + { + op.ClusteredIndex.Should().NotBeNull(); + } + else + { + op.ClusteredIndex.Should().BeNull(); + } op.Collation.Should().BeSameAs(options.Collation); op.IndexOptionDefaults.ToBsonDocument().Should().Be(options.IndexOptionDefaults.ToBsonDocument()); op.MaxDocuments.Should().Be(options.MaxDocuments); @@ -515,6 +531,7 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt op.AutoIndexId.Should().Be(options.AutoIndexId); #pragma warning restore op.Capped.Should().Be(options.Capped); + op.ClusteredIndex.Should().BeNull(); op.Collation.Should().BeSameAs(options.Collation); op.IndexOptionDefaults.ToBsonDocument().Should().Be(options.IndexOptionDefaults.ToBsonDocument()); op.MaxDocuments.Should().Be(options.MaxDocuments); @@ -571,6 +588,7 @@ public void CreateCollection_should_execute_a_CreateCollectionOperation_when_opt op.AutoIndexId.Should().NotHaveValue(); #pragma warning restore op.Capped.Should().NotHaveValue(); + op.ClusteredIndex.Should().BeNull(); op.IndexOptionDefaults.Should().BeNull(); op.MaxDocuments.Should().NotHaveValue(); op.MaxSize.Should().NotHaveValue(); diff --git a/tests/MongoDB.Driver.Tests/Specifications/collection-management/tests/clustered-indexes.json b/tests/MongoDB.Driver.Tests/Specifications/collection-management/tests/clustered-indexes.json new file mode 100644 index 00000000000..97afce74e01 --- /dev/null +++ b/tests/MongoDB.Driver.Tests/Specifications/collection-management/tests/clustered-indexes.json @@ -0,0 +1,176 @@ +{ + "description": "clustered-indexes", + "schemaVersion": "1.0", + "runOnRequirements": [ + { + "minServerVersion": "5.3" + } + ], + "createEntities": [ + { + "client": { + "id": "client0" + } + }, + { + "database": { + "id": "database0", + "client": "client0", + "databaseName": "ts-tests" + } + }, + { + "collection": { + "id": "collection0", + "database": "database0", + "collectionName": "test" + } + } + ], + "initialData": [ + { + "collectionName": "test", + "databaseName": "ts-tests", + "documents": [] + } + ], + "tests": [ + { + "description": "createCollection with clusteredIndex", + "operations": [ + { + "name": "dropCollection", + "object": "database0", + "arguments": { + "collection": "test" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "test", + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index" + } + } + }, + { + "name": "assertCollectionExists", + "object": "testRunner", + "arguments": { + "databaseName": "ts-tests", + "collectionName": "test" + } + } + ] + }, + { + "description": "listCollections includes clusteredIndex", + "operations": [ + { + "name": "dropCollection", + "object": "database0", + "arguments": { + "collection": "test" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "test", + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index" + } + } + }, + { + "name": "listCollections", + "object": "database0", + "arguments": { + "filter": { + "name": { + "$eq": "test" + } + } + }, + "expectResult": [ + { + "name": "test", + "options": { + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index", + "v": { + "$$type": [ + "int", + "long" + ] + } + } + } + } + ] + } + ] + }, + { + "description": "listIndexes returns the index", + "operations": [ + { + "name": "dropCollection", + "object": "database0", + "arguments": { + "collection": "test" + } + }, + { + "name": "createCollection", + "object": "database0", + "arguments": { + "collection": "test", + "clusteredIndex": { + "key": { + "_id": 1 + }, + "unique": true, + "name": "test index" + } + } + }, + { + "name": "listIndexes", + "object": "collection0", + "expectResult": [ + { + "key": { + "_id": 1 + }, + "name": "test index", + "clustered": true, + "unique": true, + "v": { + "$$type": [ + "int", + "long" + ] + } + } + ] + } + ] + } + ] +} diff --git a/tests/MongoDB.Driver.Tests/Specifications/collection-management/tests/clustered-indexes.yml b/tests/MongoDB.Driver.Tests/Specifications/collection-management/tests/clustered-indexes.yml new file mode 100644 index 00000000000..b22f05a6803 --- /dev/null +++ b/tests/MongoDB.Driver.Tests/Specifications/collection-management/tests/clustered-indexes.yml @@ -0,0 +1,94 @@ +description: "clustered-indexes" + +schemaVersion: "1.0" + +runOnRequirements: + - minServerVersion: "5.3" + +createEntities: + - client: + id: &client0 client0 + - database: + id: &database0 database0 + client: *client0 + databaseName: &database0Name ts-tests + - collection: + id: &collection0 collection0 + database: *database0 + collectionName: &collection0Name test + +initialData: + - collectionName: *collection0Name + databaseName: *database0Name + documents: [] + +tests: + - description: "createCollection with clusteredIndex" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0Name + - name: createCollection + object: *database0 + arguments: + collection: *collection0Name + clusteredIndex: + key: { _id: 1 } + unique: true + name: &index0Name "test index" + - name: assertCollectionExists + object: testRunner + arguments: + databaseName: *database0Name + collectionName: *collection0Name + + - description: "listCollections includes clusteredIndex" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0Name + - name: createCollection + object: *database0 + arguments: + collection: *collection0Name + clusteredIndex: + key: { _id: 1 } + unique: true + name: &index0Name "test index" + - name: listCollections + object: *database0 + arguments: + filter: { name: { $eq: *collection0Name } } + expectResult: + - name: *collection0Name + options: + clusteredIndex: + key: { _id: 1 } + unique: true + name: *index0Name + v: { $$type: [ int, long ] } + + - description: "listIndexes returns the index" + operations: + - name: dropCollection + object: *database0 + arguments: + collection: *collection0Name + - name: createCollection + object: *database0 + arguments: + collection: *collection0Name + clusteredIndex: + key: { _id: 1 } + unique: true + name: *index0Name + - name: listIndexes + object: *collection0 + expectResult: + - key: { _id: 1 } + name: *index0Name + clustered: true + unique: true + v: { $$type: [ int, long ] } diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedCreateCollectionOperation.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedCreateCollectionOperation.cs index 55787cfb09b..6daf7bf59f9 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedCreateCollectionOperation.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedCreateCollectionOperation.cs @@ -170,11 +170,21 @@ public IUnifiedEntityTestOperation Build(string targetDatabaseId, BsonDocument a IClientSessionHandle session = null; TimeSpan? expireAfter = null; TimeSeriesOptions timeSeriesOptions = null; + ClusteredIndexOptions clusteredIndex = null; foreach (var argument in arguments) { switch (argument.Name) { + case "clusteredIndex": + var clusteredIndexSpecification = argument.Value.AsBsonDocument; + clusteredIndex = new ClusteredIndexOptions + { + Key = clusteredIndexSpecification["key"].AsBsonDocument, + Unique = clusteredIndexSpecification["unique"].AsBoolean, + Name = clusteredIndexSpecification["name"].AsString + }; + break; case "collection": name = argument.Value.AsString; break; @@ -213,10 +223,10 @@ public IUnifiedEntityTestOperation Build(string targetDatabaseId, BsonDocument a if (viewOn == null && pipeline == null) { - var options = new CreateCollectionOptions { ExpireAfter = expireAfter, TimeSeriesOptions = timeSeriesOptions }; + var options = new CreateCollectionOptions { ExpireAfter = expireAfter, TimeSeriesOptions = timeSeriesOptions, ClusteredIndex = clusteredIndex }; return new UnifiedCreateCollectionOperation(session, database, name, options); } - if (viewOn != null && expireAfter == null && timeSeriesOptions == null) + if (viewOn != null && expireAfter == null && timeSeriesOptions == null && clusteredIndex == null) { var options = new CreateViewOptions(); return new UnifiedCreateViewOperation(session, database, name, viewOn, pipeline, options); diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListCollectionsOperation.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListCollectionsOperation.cs index 45c1bf896b3..28101f7f7ff 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListCollectionsOperation.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListCollectionsOperation.cs @@ -45,9 +45,9 @@ public OperationResult Execute(CancellationToken cancellationToken) ? _database.ListCollections(_options, cancellationToken) : _database.ListCollections(_session, _options, cancellationToken); - _ = cursor.ToList(cancellationToken); + var collections = cursor.ToList(cancellationToken); - return OperationResult.Empty(); + return OperationResult.FromResult(new BsonArray(collections)); } catch (Exception ex) { @@ -63,9 +63,9 @@ public async Task ExecuteAsync(CancellationToken cancellationTo ? await _database.ListCollectionsAsync(_options, cancellationToken) : await _database.ListCollectionsAsync(_session, _options, cancellationToken); - _ = await cursor.ToListAsync(cancellationToken); + var collections = await cursor.ToListAsync(cancellationToken); - return OperationResult.Empty(); + return OperationResult.FromResult(new BsonArray(collections)); } catch (Exception ex) { diff --git a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListIndexesOperation.cs b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListIndexesOperation.cs index 441dfebcbfd..0a3be94c501 100644 --- a/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListIndexesOperation.cs +++ b/tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedListIndexesOperation.cs @@ -45,9 +45,9 @@ public OperationResult Execute(CancellationToken cancellationToken) ? _collection.Indexes.List(_listIndexesOptions, cancellationToken) : _collection.Indexes.List(_session, _listIndexesOptions, cancellationToken); - _ = cursor.ToList(cancellationToken); + var indexes = cursor.ToList(cancellationToken); - return OperationResult.Empty(); + return OperationResult.FromResult(new BsonArray(indexes)); } catch (Exception ex) { @@ -63,9 +63,9 @@ public async Task ExecuteAsync(CancellationToken cancellationTo ? await _collection.Indexes.ListAsync(_listIndexesOptions, cancellationToken) : await _collection.Indexes.ListAsync(_session, _listIndexesOptions, cancellationToken); - _ = await cursor.ToListAsync(cancellationToken); + var indexes = await cursor.ToListAsync(cancellationToken); - return OperationResult.Empty(); + return OperationResult.FromResult(new BsonArray(indexes)); } catch (Exception ex) {