IMongoDatabase.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* Copyright 2010-2017 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. namespace MongoDB.Driver
  21. {
  22. /// <summary>
  23. /// Represents a database in MongoDB.
  24. /// </summary>
  25. /// <remarks>
  26. /// This interface is not guaranteed to remain stable. Implementors should use
  27. /// <see cref="MongoDatabaseBase" />.
  28. /// </remarks>
  29. public interface IMongoDatabase
  30. {
  31. /// <summary>
  32. /// Gets the client.
  33. /// </summary>
  34. IMongoClient Client { get; }
  35. /// <summary>
  36. /// Gets the namespace of the database.
  37. /// </summary>
  38. DatabaseNamespace DatabaseNamespace { get; }
  39. /// <summary>
  40. /// Gets the settings.
  41. /// </summary>
  42. MongoDatabaseSettings Settings { get; }
  43. /// <summary>
  44. /// Creates the collection with the specified name.
  45. /// </summary>
  46. /// <param name="name">The name.</param>
  47. /// <param name="options">The options.</param>
  48. /// <param name="cancellationToken">The cancellation token.</param>
  49. void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  50. /// <summary>
  51. /// Creates the collection with the specified name.
  52. /// </summary>
  53. /// <param name="name">The name.</param>
  54. /// <param name="options">The options.</param>
  55. /// <param name="cancellationToken">The cancellation token.</param>
  56. /// <returns>A task.</returns>
  57. Task CreateCollectionAsync(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  58. /// <summary>
  59. /// Creates a view.
  60. /// </summary>
  61. /// <typeparam name="TDocument">The type of the input documents.</typeparam>
  62. /// <typeparam name="TResult">The type of the pipeline result documents.</typeparam>
  63. /// <param name="viewName">The name of the view.</param>
  64. /// <param name="viewOn">The name of the collection that the view is on.</param>
  65. /// <param name="pipeline">The pipeline.</param>
  66. /// <param name="options">The options.</param>
  67. /// <param name="cancellationToken">The cancellation token.</param>
  68. void CreateView<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken));
  69. /// <summary>
  70. /// Creates a view.
  71. /// </summary>
  72. /// <typeparam name="TDocument">The type of the input documents.</typeparam>
  73. /// <typeparam name="TResult">The type of the pipeline result documents.</typeparam>
  74. /// <param name="viewName">The name of the view.</param>
  75. /// <param name="viewOn">The name of the collection that the view is on.</param>
  76. /// <param name="pipeline">The pipeline.</param>
  77. /// <param name="options">The options.</param>
  78. /// <param name="cancellationToken">The cancellation token.</param>
  79. /// <returns>A task.</returns>
  80. Task CreateViewAsync<TDocument, TResult>(string viewName, string viewOn, PipelineDefinition<TDocument, TResult> pipeline, CreateViewOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken));
  81. /// <summary>
  82. /// Drops the collection with the specified name.
  83. /// </summary>
  84. /// <param name="name">The name of the collection to drop.</param>
  85. /// <param name="cancellationToken">The cancellation token.</param>
  86. void DropCollection(string name, CancellationToken cancellationToken = default(CancellationToken));
  87. /// <summary>
  88. /// Drops the collection with the specified name.
  89. /// </summary>
  90. /// <param name="name">The name of the collection to drop.</param>
  91. /// <param name="cancellationToken">The cancellation token.</param>
  92. /// <returns>A task.</returns>
  93. Task DropCollectionAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
  94. /// <summary>
  95. /// Gets a collection.
  96. /// </summary>
  97. /// <typeparam name="TDocument">The document type.</typeparam>
  98. /// <param name="name">The name of the collection.</param>
  99. /// <param name="settings">The settings.</param>
  100. /// <returns>An implementation of a collection.</returns>
  101. IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCollectionSettings settings = null);
  102. /// <summary>
  103. /// Lists all the collections on the server.
  104. /// </summary>
  105. /// <param name="options">The options.</param>
  106. /// <param name="cancellationToken">The cancellation token.</param>
  107. /// <returns>A cursor.</returns>
  108. IAsyncCursor<BsonDocument> ListCollections(ListCollectionsOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  109. /// <summary>
  110. /// Lists all the collections on the server.
  111. /// </summary>
  112. /// <param name="options">The options.</param>
  113. /// <param name="cancellationToken">The cancellation token.</param>
  114. /// <returns>A Task whose result is a cursor.</returns>
  115. Task<IAsyncCursor<BsonDocument>> ListCollectionsAsync(ListCollectionsOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  116. /// <summary>
  117. /// Renames the collection.
  118. /// </summary>
  119. /// <param name="oldName">The old name.</param>
  120. /// <param name="newName">The new name.</param>
  121. /// <param name="options">The options.</param>
  122. /// <param name="cancellationToken">The cancellation token.</param>
  123. void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  124. /// <summary>
  125. /// Renames the collection.
  126. /// </summary>
  127. /// <param name="oldName">The old name.</param>
  128. /// <param name="newName">The new name.</param>
  129. /// <param name="options">The options.</param>
  130. /// <param name="cancellationToken">The cancellation token.</param>
  131. /// <returns>A task.</returns>
  132. Task RenameCollectionAsync(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  133. /// <summary>
  134. /// Runs a command.
  135. /// </summary>
  136. /// <typeparam name="TResult">The result type of the command.</typeparam>
  137. /// <param name="command">The command.</param>
  138. /// <param name="readPreference">The read preference.</param>
  139. /// <param name="cancellationToken">The cancellation token.</param>
  140. /// <returns>
  141. /// The result of the command.
  142. /// </returns>
  143. TResult RunCommand<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default(CancellationToken));
  144. /// <summary>
  145. /// Runs a command.
  146. /// </summary>
  147. /// <typeparam name="TResult">The result type of the command.</typeparam>
  148. /// <param name="command">The command.</param>
  149. /// <param name="readPreference">The read preference.</param>
  150. /// <param name="cancellationToken">The cancellation token.</param>
  151. /// <returns>
  152. /// The result of the command.
  153. /// </returns>
  154. Task<TResult> RunCommandAsync<TResult>(Command<TResult> command, ReadPreference readPreference = null, CancellationToken cancellationToken = default(CancellationToken));
  155. /// <summary>
  156. /// Returns a new IMongoDatabase instance with a different read concern setting.
  157. /// </summary>
  158. /// <param name="readConcern">The read concern.</param>
  159. /// <returns>A new IMongoDatabase instance with a different read concern setting.</returns>
  160. IMongoDatabase WithReadConcern(ReadConcern readConcern);
  161. /// <summary>
  162. /// Returns a new IMongoDatabase instance with a different read preference setting.
  163. /// </summary>
  164. /// <param name="readPreference">The read preference.</param>
  165. /// <returns>A new IMongoDatabase instance with a different read preference setting.</returns>
  166. IMongoDatabase WithReadPreference(ReadPreference readPreference);
  167. /// <summary>
  168. /// Returns a new IMongoDatabase instance with a different write concern setting.
  169. /// </summary>
  170. /// <param name="writeConcern">The write concern.</param>
  171. /// <returns>A new IMongoDatabase instance with a different write concern setting.</returns>
  172. IMongoDatabase WithWriteConcern(WriteConcern writeConcern);
  173. }
  174. }