IMongoClient.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /* Copyright 2013-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.Collections.Generic;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using MongoDB.Bson;
  19. using MongoDB.Driver.Core.Clusters;
  20. namespace MongoDB.Driver
  21. {
  22. /// <summary>
  23. /// The client interface to MongoDB.
  24. /// </summary>
  25. /// <remarks>
  26. /// This interface is not guaranteed to remain stable. Implementors should use
  27. /// <see cref="MongoClientBase"/>.
  28. /// </remarks>
  29. public interface IMongoClient
  30. {
  31. /// <summary>
  32. /// Gets the cluster.
  33. /// </summary>
  34. /// <value>
  35. /// The cluster.
  36. /// </value>
  37. ICluster Cluster { get; }
  38. /// <summary>
  39. /// Gets the settings.
  40. /// </summary>
  41. MongoClientSettings Settings { get; }
  42. /// <summary>
  43. /// Drops the database with the specified name.
  44. /// </summary>
  45. /// <param name="name">The name of the database to drop.</param>
  46. /// <param name="cancellationToken">The cancellation token.</param>
  47. void DropDatabase(string name, CancellationToken cancellationToken = default(CancellationToken));
  48. /// <summary>
  49. /// Drops the database with the specified name.
  50. /// </summary>
  51. /// <param name="session">The session.</param>
  52. /// <param name="name">The name of the database to drop.</param>
  53. /// <param name="cancellationToken">The cancellation token.</param>
  54. void DropDatabase(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken));
  55. /// <summary>
  56. /// Drops the database with the specified name.
  57. /// </summary>
  58. /// <param name="name">The name of the database to drop.</param>
  59. /// <param name="cancellationToken">The cancellation token.</param>
  60. /// <returns>A task.</returns>
  61. Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
  62. /// <summary>
  63. /// Drops the database with the specified name.
  64. /// </summary>
  65. /// <param name="session">The session.</param>
  66. /// <param name="name">The name of the database to drop.</param>
  67. /// <param name="cancellationToken">The cancellation token.</param>
  68. /// <returns>
  69. /// A task.
  70. /// </returns>
  71. Task DropDatabaseAsync(IClientSessionHandle session, string name, CancellationToken cancellationToken = default(CancellationToken));
  72. /// <summary>
  73. /// Gets a database.
  74. /// </summary>
  75. /// <param name="name">The name of the database.</param>
  76. /// <param name="settings">The database settings.</param>
  77. /// <returns>An implementation of a database.</returns>
  78. IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null);
  79. /// <summary>
  80. /// Returns the names of the databases on the server.
  81. /// </summary>
  82. /// <param name="cancellationToken">The cancellation token.</param>
  83. /// <returns>The database names.</returns>
  84. IAsyncCursor<string> ListDatabaseNames(
  85. CancellationToken cancellationToken = default(CancellationToken));
  86. /// <summary>
  87. /// Returns the names of the databases on the server.
  88. /// </summary>
  89. /// <param name="session">The session.</param>
  90. /// <param name="cancellationToken">The cancellation token.</param>
  91. /// <returns>The database names.</returns>
  92. IAsyncCursor<string> ListDatabaseNames(
  93. IClientSessionHandle session,
  94. CancellationToken cancellationToken = default(CancellationToken));
  95. /// <summary>
  96. /// Returns the names of the databases on the server.
  97. /// </summary>
  98. /// <param name="cancellationToken">The cancellation token.</param>
  99. /// <returns>The database names.</returns>
  100. Task<IAsyncCursor<string>> ListDatabaseNamesAsync(
  101. CancellationToken cancellationToken = default(CancellationToken));
  102. /// <summary>
  103. /// Returns the names of the databases on the server.
  104. /// </summary>
  105. /// <param name="session">The session.</param>
  106. /// <param name="cancellationToken">The cancellation token.</param>
  107. /// <returns>The database names.</returns>
  108. Task<IAsyncCursor<string>> ListDatabaseNamesAsync(
  109. IClientSessionHandle session,
  110. CancellationToken cancellationToken = default(CancellationToken));
  111. /// <summary>
  112. /// Lists the databases on the server.
  113. /// </summary>
  114. /// <param name="cancellationToken">The cancellation token.</param>
  115. /// <returns>A cursor.</returns>
  116. IAsyncCursor<BsonDocument> ListDatabases(
  117. CancellationToken cancellationToken = default(CancellationToken));
  118. /// <summary>
  119. /// Lists the databases on the server.
  120. /// </summary>
  121. /// <param name="options">The options.</param>
  122. /// <param name="cancellationToken">The cancellation token.</param>
  123. /// <returns>A cursor.</returns>
  124. IAsyncCursor<BsonDocument> ListDatabases(
  125. ListDatabasesOptions options,
  126. CancellationToken cancellationToken = default(CancellationToken));
  127. /// <summary>
  128. /// Lists the databases on the server.
  129. /// </summary>
  130. /// <param name="session">The session.</param>
  131. /// <param name="cancellationToken">The cancellation token.</param>
  132. /// <returns>
  133. /// A cursor.
  134. /// </returns>
  135. IAsyncCursor<BsonDocument> ListDatabases(
  136. IClientSessionHandle session,
  137. CancellationToken cancellationToken = default(CancellationToken));
  138. /// <summary>
  139. /// Lists the databases on the server.
  140. /// </summary>
  141. /// <param name="session">The session.</param>
  142. /// <param name="options">The options.</param>
  143. /// <param name="cancellationToken">The cancellation token.</param>
  144. /// <returns>
  145. /// A cursor.
  146. /// </returns>
  147. IAsyncCursor<BsonDocument> ListDatabases(
  148. IClientSessionHandle session,
  149. ListDatabasesOptions options,
  150. CancellationToken cancellationToken = default(CancellationToken));
  151. /// <summary>
  152. /// Lists the databases on the server.
  153. /// </summary>
  154. /// <param name="cancellationToken">The cancellation token.</param>
  155. /// <returns>A Task whose result is a cursor.</returns>
  156. Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(
  157. CancellationToken cancellationToken = default(CancellationToken));
  158. /// <summary>
  159. /// Lists the databases on the server.
  160. /// </summary>
  161. /// <param name="cancellationToken">The cancellation token.</param>
  162. /// <param name="options">The options.</param>
  163. /// <returns>A Task whose result is a cursor.</returns>
  164. Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(
  165. ListDatabasesOptions options,
  166. CancellationToken cancellationToken = default(CancellationToken));
  167. /// <summary>
  168. /// Lists the databases on the server.
  169. /// </summary>
  170. /// <param name="session">The session.</param>
  171. /// <param name="cancellationToken">The cancellation token.</param>
  172. /// <returns>
  173. /// A Task whose result is a cursor.
  174. /// </returns>
  175. Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(
  176. IClientSessionHandle session,
  177. CancellationToken cancellationToken = default(CancellationToken));
  178. /// <summary>
  179. /// Lists the databases on the server.
  180. /// </summary>
  181. /// <param name="session">The session.</param>
  182. /// <param name="options">The options.</param>
  183. /// <param name="cancellationToken">The cancellation token.</param>
  184. /// <returns>
  185. /// A Task whose result is a cursor.
  186. /// </returns>
  187. Task<IAsyncCursor<BsonDocument>> ListDatabasesAsync(
  188. IClientSessionHandle session,
  189. ListDatabasesOptions options,
  190. CancellationToken cancellationToken = default(CancellationToken));
  191. /// <summary>
  192. /// Starts a client session.
  193. /// </summary>
  194. /// <param name="options">The session options.</param>
  195. /// <param name="cancellationToken">The cancellation token.</param>
  196. /// <returns>
  197. /// A client session.
  198. /// </returns>
  199. IClientSessionHandle StartSession(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  200. /// <summary>
  201. /// Starts a client session.
  202. /// </summary>
  203. /// <param name="options">The session options.</param>
  204. /// <param name="cancellationToken">The cancellation token.</param>
  205. /// <returns>
  206. /// A Task whose result is a client session.
  207. /// </returns>
  208. Task<IClientSessionHandle> StartSessionAsync(ClientSessionOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  209. /// <summary>
  210. /// Watches changes on all collections in all databases.
  211. /// </summary>
  212. /// <typeparam name="TResult">The type of the result.</typeparam>
  213. /// <param name="pipeline">The pipeline.</param>
  214. /// <param name="options">The options.</param>
  215. /// <param name="cancellationToken">The cancellation token.</param>
  216. /// <returns>
  217. /// A change stream.
  218. /// </returns>
  219. IAsyncCursor<TResult> Watch<TResult>(
  220. PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
  221. ChangeStreamOptions options = null,
  222. CancellationToken cancellationToken = default(CancellationToken));
  223. /// <summary>
  224. /// Watches changes on all collections in all databases.
  225. /// </summary>
  226. /// <typeparam name="TResult">The type of the result.</typeparam>
  227. /// <param name="session">The session.</param>
  228. /// <param name="pipeline">The pipeline.</param>
  229. /// <param name="options">The options.</param>
  230. /// <param name="cancellationToken">The cancellation token.</param>
  231. /// <returns>
  232. /// A change stream.
  233. /// </returns>
  234. IAsyncCursor<TResult> Watch<TResult>(
  235. IClientSessionHandle session,
  236. PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
  237. ChangeStreamOptions options = null,
  238. CancellationToken cancellationToken = default(CancellationToken));
  239. /// <summary>
  240. /// Watches changes on all collections in all databases.
  241. /// </summary>
  242. /// <typeparam name="TResult">The type of the result.</typeparam>
  243. /// <param name="pipeline">The pipeline.</param>
  244. /// <param name="options">The options.</param>
  245. /// <param name="cancellationToken">The cancellation token.</param>
  246. /// <returns>
  247. /// A change stream.
  248. /// </returns>
  249. Task<IAsyncCursor<TResult>> WatchAsync<TResult>(
  250. PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
  251. ChangeStreamOptions options = null,
  252. CancellationToken cancellationToken = default(CancellationToken));
  253. /// <summary>
  254. /// Watches changes on all collections in all databases.
  255. /// </summary>
  256. /// <typeparam name="TResult">The type of the result.</typeparam>
  257. /// <param name="session">The session.</param>
  258. /// <param name="pipeline">The pipeline.</param>
  259. /// <param name="options">The options.</param>
  260. /// <param name="cancellationToken">The cancellation token.</param>
  261. /// <returns>
  262. /// A change stream.
  263. /// </returns>
  264. Task<IAsyncCursor<TResult>> WatchAsync<TResult>(
  265. IClientSessionHandle session,
  266. PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult> pipeline,
  267. ChangeStreamOptions options = null,
  268. CancellationToken cancellationToken = default(CancellationToken));
  269. /// <summary>
  270. /// Returns a new IMongoClient instance with a different read concern setting.
  271. /// </summary>
  272. /// <param name="readConcern">The read concern.</param>
  273. /// <returns>A new IMongoClient instance with a different read concern setting.</returns>
  274. IMongoClient WithReadConcern(ReadConcern readConcern);
  275. /// <summary>
  276. /// Returns a new IMongoClient instance with a different read preference setting.
  277. /// </summary>
  278. /// <param name="readPreference">The read preference.</param>
  279. /// <returns>A new IMongoClient instance with a different read preference setting.</returns>
  280. IMongoClient WithReadPreference(ReadPreference readPreference);
  281. /// <summary>
  282. /// Returns a new IMongoClient instance with a different write concern setting.
  283. /// </summary>
  284. /// <param name="writeConcern">The write concern.</param>
  285. /// <returns>A new IMongoClient instance with a different write concern setting.</returns>
  286. IMongoClient WithWriteConcern(WriteConcern writeConcern);
  287. }
  288. }