IMongoIndexManager.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* Copyright 2010-2015 MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System.Collections.Generic;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using MongoDB.Bson;
  19. using MongoDB.Bson.Serialization;
  20. namespace MongoDB.Driver
  21. {
  22. /// <summary>
  23. /// An interface representing methods used to create, delete and modify indexes.
  24. /// </summary>
  25. /// <remarks>
  26. /// This interface is not guaranteed to remain stable. Implementors should use
  27. /// <see cref="MongoIndexManagerBase{TDocument}"/>.
  28. /// </remarks>
  29. /// <typeparam name="TDocument">The type of the document.</typeparam>
  30. public interface IMongoIndexManager<TDocument>
  31. {
  32. /// <summary>
  33. /// Gets the namespace of the collection.
  34. /// </summary>
  35. CollectionNamespace CollectionNamespace { get; }
  36. /// <summary>
  37. /// Gets the document serializer.
  38. /// </summary>
  39. IBsonSerializer<TDocument> DocumentSerializer { get; }
  40. /// <summary>
  41. /// Gets the collection settings.
  42. /// </summary>
  43. MongoCollectionSettings Settings { get; }
  44. /// <summary>
  45. /// Creates an index.
  46. /// </summary>
  47. /// <param name="keys">The keys.</param>
  48. /// <param name="options">The options.</param>
  49. /// <param name="cancellationToken">The cancellation token.</param>
  50. /// <returns>
  51. /// The name of the index that was created.
  52. /// </returns>
  53. string CreateOne(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  54. /// <summary>
  55. /// Creates an index.
  56. /// </summary>
  57. /// <param name="keys">The keys.</param>
  58. /// <param name="options">The options.</param>
  59. /// <param name="cancellationToken">The cancellation token.</param>
  60. /// <returns>
  61. /// A task whose result is the name of the index that was created.
  62. /// </returns>
  63. Task<string> CreateOneAsync(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  64. /// <summary>
  65. /// Creates multiple indexes.
  66. /// </summary>
  67. /// <param name="models">The models defining each of the indexes.</param>
  68. /// <param name="cancellationToken">The cancellation token.</param>
  69. /// <returns>
  70. /// An <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  71. /// </returns>
  72. IEnumerable<string> CreateMany(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken));
  73. /// <summary>
  74. /// Creates multiple indexes.
  75. /// </summary>
  76. /// <param name="models">The models defining each of the indexes.</param>
  77. /// <param name="cancellationToken">The cancellation token.</param>
  78. /// <returns>
  79. /// A task whose result is an <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  80. /// </returns>
  81. Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken));
  82. /// <summary>
  83. /// Drops all the indexes.
  84. /// </summary>
  85. /// <param name="cancellationToken">The cancellation token.</param>
  86. void DropAll(CancellationToken cancellationToken = default(CancellationToken));
  87. /// <summary>
  88. /// Drops all the indexes.
  89. /// </summary>
  90. /// <param name="cancellationToken">The cancellation token.</param>
  91. /// <returns>A task.</returns>
  92. Task DropAllAsync(CancellationToken cancellationToken = default(CancellationToken));
  93. /// <summary>
  94. /// Drops an index by its name.
  95. /// </summary>
  96. /// <param name="name">The name.</param>
  97. /// <param name="cancellationToken">The cancellation token.</param>
  98. void DropOne(string name, CancellationToken cancellationToken = default(CancellationToken));
  99. /// <summary>
  100. /// Drops an index by its name.
  101. /// </summary>
  102. /// <param name="name">The name.</param>
  103. /// <param name="cancellationToken">The cancellation token.</param>
  104. /// <returns>A task.</returns>
  105. Task DropOneAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
  106. /// <summary>
  107. /// Lists the indexes.
  108. /// </summary>
  109. /// <param name="cancellationToken">The cancellation token.</param>
  110. /// <returns>A cursor.</returns>
  111. IAsyncCursor<BsonDocument> List(CancellationToken cancellationToken = default(CancellationToken));
  112. /// <summary>
  113. /// Lists the indexes.
  114. /// </summary>
  115. /// <param name="cancellationToken">The cancellation token.</param>
  116. /// <returns>A Task whose result is a cursor.</returns>
  117. Task<IAsyncCursor<BsonDocument>> ListAsync(CancellationToken cancellationToken = default(CancellationToken));
  118. }
  119. }