IMongoIndexManager.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /* Copyright 2010-present 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;
  16. using System.Collections.Generic;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using MongoDB.Bson;
  20. using MongoDB.Bson.Serialization;
  21. namespace MongoDB.Driver
  22. {
  23. /// <summary>
  24. /// An interface representing methods used to create, delete and modify indexes.
  25. /// </summary>
  26. /// <remarks>
  27. /// This interface is not guaranteed to remain stable. Implementors should use
  28. /// <see cref="MongoIndexManagerBase{TDocument}"/>.
  29. /// </remarks>
  30. /// <typeparam name="TDocument">The type of the document.</typeparam>
  31. public interface IMongoIndexManager<TDocument>
  32. {
  33. /// <summary>
  34. /// Gets the namespace of the collection.
  35. /// </summary>
  36. CollectionNamespace CollectionNamespace { get; }
  37. /// <summary>
  38. /// Gets the document serializer.
  39. /// </summary>
  40. IBsonSerializer<TDocument> DocumentSerializer { get; }
  41. /// <summary>
  42. /// Gets the collection settings.
  43. /// </summary>
  44. MongoCollectionSettings Settings { get; }
  45. /// <summary>
  46. /// Creates multiple indexes.
  47. /// </summary>
  48. /// <param name="models">The models defining each of the indexes.</param>
  49. /// <param name="cancellationToken">The cancellation token.</param>
  50. /// <returns>
  51. /// An <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  52. /// </returns>
  53. IEnumerable<string> CreateMany(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken));
  54. /// <summary>
  55. /// Creates multiple indexes.
  56. /// </summary>
  57. /// <param name="models">The models defining each of the indexes.</param>
  58. /// <param name="options">The options for create multiple indexes.</param>
  59. /// <param name="cancellationToken">The cancellation token.</param>
  60. /// <returns>
  61. /// An <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  62. /// </returns>
  63. IEnumerable<string> CreateMany(
  64. IEnumerable<CreateIndexModel<TDocument>> models,
  65. CreateManyIndexesOptions options,
  66. CancellationToken cancellationToken = default(CancellationToken));
  67. /// <summary>
  68. /// Creates multiple indexes.
  69. /// </summary>
  70. /// <param name="session">The session.</param>
  71. /// <param name="models">The models defining each of the indexes.</param>
  72. /// <param name="cancellationToken">The cancellation token.</param>
  73. /// <returns>
  74. /// An <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  75. /// </returns>
  76. IEnumerable<string> CreateMany(IClientSessionHandle session, IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken));
  77. /// <summary>
  78. /// Creates multiple indexes.
  79. /// </summary>
  80. /// <param name="session">The session.</param>
  81. /// <param name="models">The models defining each of the indexes.</param>
  82. /// <param name="options">The options for create multiple indexes.</param>
  83. /// <param name="cancellationToken">The cancellation token.</param>
  84. /// <returns>
  85. /// An <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  86. /// </returns>
  87. IEnumerable<string> CreateMany(
  88. IClientSessionHandle session,
  89. IEnumerable<CreateIndexModel<TDocument>> models,
  90. CreateManyIndexesOptions options,
  91. CancellationToken cancellationToken = default(CancellationToken));
  92. /// <summary>
  93. /// Creates multiple indexes.
  94. /// </summary>
  95. /// <param name="models">The models defining each of the indexes.</param>
  96. /// <param name="cancellationToken">The cancellation token.</param>
  97. /// <returns>
  98. /// A task whose result is an <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  99. /// </returns>
  100. Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken));
  101. /// <summary>
  102. /// Creates multiple indexes.
  103. /// </summary>
  104. /// <param name="models">The models defining each of the indexes.</param>
  105. /// <param name="options">The options for create multiple indexes.</param>
  106. /// <param name="cancellationToken">The cancellation token.</param>
  107. /// <returns>
  108. /// A task whose result is an <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  109. /// </returns>
  110. Task<IEnumerable<string>> CreateManyAsync(
  111. IEnumerable<CreateIndexModel<TDocument>> models,
  112. CreateManyIndexesOptions options,
  113. CancellationToken cancellationToken = default(CancellationToken));
  114. /// <summary>
  115. /// Creates multiple indexes.
  116. /// </summary>
  117. /// <param name="session">The session.</param>
  118. /// <param name="models">The models defining each of the indexes.</param>
  119. /// <param name="cancellationToken">The cancellation token.</param>
  120. /// <returns>
  121. /// A task whose result is an <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  122. /// </returns>
  123. Task<IEnumerable<string>> CreateManyAsync(IClientSessionHandle session, IEnumerable<CreateIndexModel<TDocument>> models, CancellationToken cancellationToken = default(CancellationToken));
  124. /// <summary>
  125. /// Creates multiple indexes.
  126. /// </summary>
  127. /// <param name="session">The session.</param>
  128. /// <param name="models">The models defining each of the indexes.</param>
  129. /// <param name="options">The options for create multiple indexes.</param>
  130. /// <param name="cancellationToken">The cancellation token.</param>
  131. /// <returns>
  132. /// A task whose result is an <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
  133. /// </returns>
  134. Task<IEnumerable<string>> CreateManyAsync(
  135. IClientSessionHandle session,
  136. IEnumerable<CreateIndexModel<TDocument>> models,
  137. CreateManyIndexesOptions options,
  138. CancellationToken cancellationToken = default(CancellationToken));
  139. /// <summary>
  140. /// Creates an index.
  141. /// </summary>
  142. /// <param name="model">The model defining the index.</param>
  143. /// <param name="options">The create index operation options.</param>
  144. /// <param name="cancellationToken">The cancellation token.</param>
  145. /// <returns>
  146. /// The name of the index that was created.
  147. /// </returns>
  148. string CreateOne(
  149. CreateIndexModel<TDocument> model,
  150. CreateOneIndexOptions options = null,
  151. CancellationToken cancellationToken = default(CancellationToken));
  152. /// <summary>
  153. /// Creates an index.
  154. /// </summary>
  155. /// <param name="keys">The keys.</param>
  156. /// <param name="options">The create index request options.</param>
  157. /// <param name="cancellationToken">The cancellation token.</param>
  158. /// <returns>
  159. /// The name of the index that was created.
  160. /// </returns>
  161. [Obsolete("Use CreateOne with a CreateIndexModel instead.")]
  162. string CreateOne(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  163. /// <summary>
  164. /// Creates an index.
  165. /// </summary>
  166. /// <param name="session">The session.</param>
  167. /// <param name="keys">The keys.</param>
  168. /// <param name="options">The create index request options.</param>
  169. /// <param name="cancellationToken">The cancellation token.</param>
  170. /// <returns>
  171. /// The name of the index that was created.
  172. /// </returns>
  173. [Obsolete("Use CreateOne with a CreateIndexModel instead.")]
  174. string CreateOne(IClientSessionHandle session, IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  175. /// <summary>
  176. /// Creates an index.
  177. /// </summary>
  178. /// <param name="session">The session.</param>
  179. /// <param name="model">The model defining the index.</param>
  180. /// <param name="options">The create index operation options.</param>
  181. /// <param name="cancellationToken">The cancellation token.</param>
  182. /// <returns>
  183. /// The name of the index that was created.
  184. /// </returns>
  185. string CreateOne(
  186. IClientSessionHandle session,
  187. CreateIndexModel<TDocument> model,
  188. CreateOneIndexOptions options = null,
  189. CancellationToken cancellationToken = default(CancellationToken));
  190. /// <summary>
  191. /// Creates an index.
  192. /// </summary>
  193. /// <param name="model">The model defining the index.</param>
  194. /// <param name="options">The create index operation options.</param>
  195. /// <param name="cancellationToken">The cancellation token.</param>
  196. /// <returns>
  197. /// A task whose result is the name of the index that was created.
  198. /// </returns>
  199. Task<string> CreateOneAsync(
  200. CreateIndexModel<TDocument> model,
  201. CreateOneIndexOptions options = null,
  202. CancellationToken cancellationToken = default(CancellationToken));
  203. /// <summary>
  204. /// Creates an index.
  205. /// </summary>
  206. /// <param name="keys">The keys.</param>
  207. /// <param name="options">The create index request options.</param>
  208. /// <param name="cancellationToken">The cancellation token.</param>
  209. /// <returns>
  210. /// A task whose result is the name of the index that was created.
  211. /// </returns>
  212. [Obsolete("Use CreateOneAsync with a CreateIndexModel instead.")]
  213. Task<string> CreateOneAsync(IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  214. /// <summary>
  215. /// Creates an index.
  216. /// </summary>
  217. /// <param name="session">The session.</param>
  218. /// <param name="keys">The keys.</param>
  219. /// <param name="options">The create index request options.</param>
  220. /// <param name="cancellationToken">The cancellation token.</param>
  221. /// <returns>
  222. /// A task whose result is the name of the index that was created.
  223. /// </returns>
  224. [Obsolete("Use CreateOneAsyc with a CreateIndexModel instead.")]
  225. Task<string> CreateOneAsync(IClientSessionHandle session, IndexKeysDefinition<TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  226. /// <summary>
  227. /// Creates an index.
  228. /// </summary>
  229. /// <param name="session">The session.</param>
  230. /// <param name="model">The model defining the index.</param>
  231. /// <param name="options">The create index operation options.</param>
  232. /// <param name="cancellationToken">The cancellation token.</param>
  233. /// <returns>
  234. /// A task whose result is the name of the index that was created.
  235. /// </returns>
  236. Task<string> CreateOneAsync(
  237. IClientSessionHandle session,
  238. CreateIndexModel<TDocument> model,
  239. CreateOneIndexOptions options = null,
  240. CancellationToken cancellationToken = default(CancellationToken));
  241. /// <summary>
  242. /// Drops all the indexes.
  243. /// </summary>
  244. /// <param name="options">The options.</param>
  245. /// <param name="cancellationToken">The cancellation token.</param>
  246. void DropAll(DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  247. /// <summary>
  248. /// Drops all the indexes.
  249. /// </summary>
  250. /// <param name="cancellationToken">The cancellation token.</param>
  251. void DropAll(CancellationToken cancellationToken = default(CancellationToken));
  252. /// <summary>
  253. /// Drops all the indexes.
  254. /// </summary>
  255. /// <param name="session">The session.</param>
  256. /// <param name="cancellationToken">The cancellation token.</param>
  257. void DropAll(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken));
  258. /// <summary>
  259. /// Drops all the indexes.
  260. /// </summary>
  261. /// <param name="session">The session.</param>
  262. /// <param name="options">The options.</param>
  263. /// <param name="cancellationToken">The cancellation token.</param>
  264. void DropAll(IClientSessionHandle session, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  265. /// <summary>
  266. /// Drops all the indexes.
  267. /// </summary>
  268. /// <param name="options">The options.</param>
  269. /// <param name="cancellationToken">The cancellation token.</param>
  270. /// <returns>
  271. /// A task.
  272. /// </returns>
  273. Task DropAllAsync(DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  274. /// <summary>
  275. /// Drops all the indexes.
  276. /// </summary>
  277. /// <param name="cancellationToken">The cancellation token.</param>
  278. /// <returns>A task.</returns>
  279. Task DropAllAsync(CancellationToken cancellationToken = default(CancellationToken));
  280. /// <summary>
  281. /// Drops all the indexes.
  282. /// </summary>
  283. /// <param name="session">The session.</param>
  284. /// <param name="cancellationToken">The cancellation token.</param>
  285. /// <returns>
  286. /// A task.
  287. /// </returns>
  288. Task DropAllAsync(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken));
  289. /// <summary>
  290. /// Drops all the indexes.
  291. /// </summary>
  292. /// <param name="session">The session.</param>
  293. /// <param name="options">The options.</param>
  294. /// <param name="cancellationToken">The cancellation token.</param>
  295. /// <returns>
  296. /// A task.
  297. /// </returns>
  298. Task DropAllAsync(IClientSessionHandle session, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  299. /// <summary>
  300. /// Drops an index by its name.
  301. /// </summary>
  302. /// <param name="name">The name.</param>
  303. /// <param name="cancellationToken">The cancellation token.</param>
  304. void DropOne(string name, CancellationToken cancellationToken = default(CancellationToken));
  305. /// <summary>
  306. /// Drops an index by its name.
  307. /// </summary>
  308. /// <param name="name">The name.</param>
  309. /// <param name="options">The options. </param>
  310. /// <param name="cancellationToken">The cancellation token.</param>
  311. void DropOne(string name, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  312. /// <summary>
  313. /// Drops an index by its name.
  314. /// </summary>
  315. /// <param name="session">The session.</param>
  316. /// <param name="name">The name.</param>
  317. /// <param name="cancellationToken">The cancellation token.</param>
  318. void DropOne(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken));
  319. /// <summary>
  320. /// Drops an index by its name.
  321. /// </summary>
  322. /// <param name="session">The session.</param>
  323. /// <param name="name">The name.</param>
  324. /// <param name="options">The options. </param>
  325. /// <param name="cancellationToken">The cancellation token.</param>
  326. void DropOne(IClientSessionHandle session, string name, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  327. /// <summary>
  328. /// Drops an index by its name.
  329. /// </summary>
  330. /// <param name="name">The name.</param>
  331. /// <param name="cancellationToken">The cancellation token.</param>
  332. /// <returns>A task.</returns>
  333. Task DropOneAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
  334. /// <summary>
  335. /// Drops an index by its name.
  336. /// </summary>
  337. /// <param name="name">The name.</param>
  338. /// <param name="options">The options. </param>
  339. /// <param name="cancellationToken">The cancellation token.</param>
  340. /// <returns>A task.</returns>
  341. Task DropOneAsync(string name, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  342. /// <summary>
  343. /// Drops an index by its name.
  344. /// </summary>
  345. /// <param name="session">The session.</param>
  346. /// <param name="name">The name.</param>
  347. /// <param name="cancellationToken">The cancellation token.</param>
  348. /// <returns>
  349. /// A task.
  350. /// </returns>
  351. Task DropOneAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken));
  352. /// <summary>
  353. /// Drops an index by its name.
  354. /// </summary>
  355. /// <param name="session">The session.</param>
  356. /// <param name="name">The name.</param>
  357. /// <param name= "options">The options. </param>
  358. /// <param name="cancellationToken">The cancellation token.</param>
  359. /// <returns>
  360. /// A task.
  361. /// </returns>
  362. Task DropOneAsync(IClientSessionHandle session, string name, DropIndexOptions options, CancellationToken cancellationToken = default(CancellationToken));
  363. /// <summary>
  364. /// Lists the indexes.
  365. /// </summary>
  366. /// <param name="cancellationToken">The cancellation token.</param>
  367. /// <returns>A cursor.</returns>
  368. IAsyncCursor<BsonDocument> List(CancellationToken cancellationToken = default(CancellationToken));
  369. /// <summary>
  370. /// Lists the indexes.
  371. /// </summary>
  372. /// <param name="session">The session.</param>
  373. /// <param name="cancellationToken">The cancellation token.</param>
  374. /// <returns>
  375. /// A cursor.
  376. /// </returns>
  377. IAsyncCursor<BsonDocument> List(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken));
  378. /// <summary>
  379. /// Lists the indexes.
  380. /// </summary>
  381. /// <param name="cancellationToken">The cancellation token.</param>
  382. /// <returns>A Task whose result is a cursor.</returns>
  383. Task<IAsyncCursor<BsonDocument>> ListAsync(CancellationToken cancellationToken = default(CancellationToken));
  384. /// <summary>
  385. /// Lists the indexes.
  386. /// </summary>
  387. /// <param name="session">The session.</param>
  388. /// <param name="cancellationToken">The cancellation token.</param>
  389. /// <returns>
  390. /// A Task whose result is a cursor.
  391. /// </returns>
  392. Task<IAsyncCursor<BsonDocument>> ListAsync(IClientSessionHandle session, CancellationToken cancellationToken = default(CancellationToken));
  393. }
  394. }