IMongoCollection.cs 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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. /// Represents a typed collection in MongoDB.
  25. /// </summary>
  26. /// <remarks>
  27. /// This interface is not guaranteed to remain stable. Implementors should use
  28. /// <see cref="MongoCollectionBase{TDocument}"/>.
  29. /// </remarks>
  30. /// <typeparam name="TDocument">The type of the documents stored in the collection.</typeparam>
  31. public interface IMongoCollection<TDocument>
  32. {
  33. /// <summary>
  34. /// Gets the namespace of the collection.
  35. /// </summary>
  36. CollectionNamespace CollectionNamespace { get; }
  37. /// <summary>
  38. /// Gets the database.
  39. /// </summary>
  40. IMongoDatabase Database { get; }
  41. /// <summary>
  42. /// Gets the document serializer.
  43. /// </summary>
  44. IBsonSerializer<TDocument> DocumentSerializer { get; }
  45. /// <summary>
  46. /// Gets the index manager.
  47. /// </summary>
  48. IMongoIndexManager<TDocument> Indexes { get; }
  49. /// <summary>
  50. /// Gets the settings.
  51. /// </summary>
  52. MongoCollectionSettings Settings { get; }
  53. /// <summary>
  54. /// Runs an aggregation pipeline.
  55. /// </summary>
  56. /// <typeparam name="TResult">The type of the result.</typeparam>
  57. /// <param name="pipeline">The pipeline.</param>
  58. /// <param name="options">The options.</param>
  59. /// <param name="cancellationToken">The cancellation token.</param>
  60. /// <returns>A cursor.</returns>
  61. IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  62. /// <summary>
  63. /// Runs an aggregation pipeline.
  64. /// </summary>
  65. /// <typeparam name="TResult">The type of the result.</typeparam>
  66. /// <param name="session">The session.</param>
  67. /// <param name="pipeline">The pipeline.</param>
  68. /// <param name="options">The options.</param>
  69. /// <param name="cancellationToken">The cancellation token.</param>
  70. /// <returns>
  71. /// A cursor.
  72. /// </returns>
  73. IAsyncCursor<TResult> Aggregate<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  74. /// <summary>
  75. /// Runs an aggregation pipeline.
  76. /// </summary>
  77. /// <typeparam name="TResult">The type of the result.</typeparam>
  78. /// <param name="pipeline">The pipeline.</param>
  79. /// <param name="options">The options.</param>
  80. /// <param name="cancellationToken">The cancellation token.</param>
  81. /// <returns>A Task whose result is a cursor.</returns>
  82. Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  83. /// <summary>
  84. /// Runs an aggregation pipeline.
  85. /// </summary>
  86. /// <typeparam name="TResult">The type of the result.</typeparam>
  87. /// <param name="session">The session.</param>
  88. /// <param name="pipeline">The pipeline.</param>
  89. /// <param name="options">The options.</param>
  90. /// <param name="cancellationToken">The cancellation token.</param>
  91. /// <returns>
  92. /// A Task whose result is a cursor.
  93. /// </returns>
  94. Task<IAsyncCursor<TResult>> AggregateAsync<TResult>(IClientSessionHandle session, PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  95. /// <summary>
  96. /// Performs multiple write operations.
  97. /// </summary>
  98. /// <param name="requests">The requests.</param>
  99. /// <param name="options">The options.</param>
  100. /// <param name="cancellationToken">The cancellation token.</param>
  101. /// <returns>The result of writing.</returns>
  102. BulkWriteResult<TDocument> BulkWrite(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  103. /// <summary>
  104. /// Performs multiple write operations.
  105. /// </summary>
  106. /// <param name="session">The session.</param>
  107. /// <param name="requests">The requests.</param>
  108. /// <param name="options">The options.</param>
  109. /// <param name="cancellationToken">The cancellation token.</param>
  110. /// <returns>
  111. /// The result of writing.
  112. /// </returns>
  113. BulkWriteResult<TDocument> BulkWrite(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  114. /// <summary>
  115. /// Performs multiple write operations.
  116. /// </summary>
  117. /// <param name="requests">The requests.</param>
  118. /// <param name="options">The options.</param>
  119. /// <param name="cancellationToken">The cancellation token.</param>
  120. /// <returns>The result of writing.</returns>
  121. Task<BulkWriteResult<TDocument>> BulkWriteAsync(IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  122. /// <summary>
  123. /// Performs multiple write operations.
  124. /// </summary>
  125. /// <param name="session">The session.</param>
  126. /// <param name="requests">The requests.</param>
  127. /// <param name="options">The options.</param>
  128. /// <param name="cancellationToken">The cancellation token.</param>
  129. /// <returns>
  130. /// The result of writing.
  131. /// </returns>
  132. Task<BulkWriteResult<TDocument>> BulkWriteAsync(IClientSessionHandle session, IEnumerable<WriteModel<TDocument>> requests, BulkWriteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  133. /// <summary>
  134. /// Counts the number of documents in the collection.
  135. /// </summary>
  136. /// <param name="filter">The filter.</param>
  137. /// <param name="options">The options.</param>
  138. /// <param name="cancellationToken">The cancellation token.</param>
  139. /// <returns>
  140. /// The number of documents in the collection.
  141. /// </returns>
  142. [Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
  143. long Count(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  144. /// <summary>
  145. /// Counts the number of documents in the collection.
  146. /// </summary>
  147. /// <param name="session">The session.</param>
  148. /// <param name="filter">The filter.</param>
  149. /// <param name="options">The options.</param>
  150. /// <param name="cancellationToken">The cancellation token.</param>
  151. /// <returns>
  152. /// The number of documents in the collection.
  153. /// </returns>
  154. [Obsolete("Use CountDocuments or EstimatedDocumentCount instead.")]
  155. long Count(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  156. /// <summary>
  157. /// Counts the number of documents in the collection.
  158. /// </summary>
  159. /// <param name="filter">The filter.</param>
  160. /// <param name="options">The options.</param>
  161. /// <param name="cancellationToken">The cancellation token.</param>
  162. /// <returns>
  163. /// The number of documents in the collection.
  164. /// </returns>
  165. [Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
  166. Task<long> CountAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  167. /// <summary>
  168. /// Counts the number of documents in the collection.
  169. /// </summary>
  170. /// <param name="session">The session.</param>
  171. /// <param name="filter">The filter.</param>
  172. /// <param name="options">The options.</param>
  173. /// <param name="cancellationToken">The cancellation token.</param>
  174. /// <returns>
  175. /// The number of documents in the collection.
  176. /// </returns>
  177. [Obsolete("Use CountDocumentsAsync or EstimatedDocumentCountAsync instead.")]
  178. Task<long> CountAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  179. /// <summary>
  180. /// Counts the number of documents in the collection.
  181. /// </summary>
  182. /// <remarks>
  183. /// Note: when migrating from Count to CountDocuments the following query operations must be replaced:
  184. ///
  185. /// <code>
  186. /// +-------------+--------------------------------+
  187. /// | Operator | Replacement |
  188. /// +=============+================================+
  189. /// | $where | $expr |
  190. /// +-------------+--------------------------------+
  191. /// | $near | $geoWithin with $center |
  192. /// +-------------+--------------------------------+
  193. /// | $nearSphere | $geoWithin with $centerSphere |
  194. /// +-------------+--------------------------------+
  195. /// </code>
  196. /// </remarks>
  197. /// <param name="filter">The filter.</param>
  198. /// <param name="options">The options.</param>
  199. /// <param name="cancellationToken">The cancellation token.</param>
  200. /// <returns>
  201. /// The number of documents in the collection.
  202. /// </returns>
  203. long CountDocuments(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  204. /// <summary>
  205. /// Counts the number of documents in the collection.
  206. /// </summary>
  207. /// <remarks>
  208. /// Note: when migrating from Count to CountDocuments the following query operations must be replaced:
  209. ///
  210. /// <code>
  211. /// +-------------+--------------------------------+
  212. /// | Operator | Replacement |
  213. /// +=============+================================+
  214. /// | $where | $expr |
  215. /// +-------------+--------------------------------+
  216. /// | $near | $geoWithin with $center |
  217. /// +-------------+--------------------------------+
  218. /// | $nearSphere | $geoWithin with $centerSphere |
  219. /// +-------------+--------------------------------+
  220. /// </code>
  221. /// </remarks>
  222. /// <param name="session">The session.</param>
  223. /// <param name="filter">The filter.</param>
  224. /// <param name="options">The options.</param>
  225. /// <param name="cancellationToken">The cancellation token.</param>
  226. /// <returns>
  227. /// The number of documents in the collection.
  228. /// </returns>
  229. long CountDocuments(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  230. /// <summary>
  231. /// Counts the number of documents in the collection.
  232. /// </summary>
  233. /// <remarks>
  234. /// Note: when migrating from CountAsync to CountDocumentsAsync the following query operations must be replaced:
  235. ///
  236. /// <code>
  237. /// +-------------+--------------------------------+
  238. /// | Operator | Replacement |
  239. /// +=============+================================+
  240. /// | $where | $expr |
  241. /// +-------------+--------------------------------+
  242. /// | $near | $geoWithin with $center |
  243. /// +-------------+--------------------------------+
  244. /// | $nearSphere | $geoWithin with $centerSphere |
  245. /// +-------------+--------------------------------+
  246. /// </code>
  247. /// </remarks>
  248. /// <param name="filter">The filter.</param>
  249. /// <param name="options">The options.</param>
  250. /// <param name="cancellationToken">The cancellation token.</param>
  251. /// <returns>
  252. /// The number of documents in the collection.
  253. /// </returns>
  254. Task<long> CountDocumentsAsync(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  255. /// <summary>
  256. /// Counts the number of documents in the collection.
  257. /// </summary>
  258. /// <remarks>
  259. /// Note: when migrating from CountAsync to CountDocumentsAsync the following query operations must be replaced:
  260. ///
  261. /// <code>
  262. /// +-------------+--------------------------------+
  263. /// | Operator | Replacement |
  264. /// +=============+================================+
  265. /// | $where | $expr |
  266. /// +-------------+--------------------------------+
  267. /// | $near | $geoWithin with $center |
  268. /// +-------------+--------------------------------+
  269. /// | $nearSphere | $geoWithin with $centerSphere |
  270. /// +-------------+--------------------------------+
  271. /// </code>
  272. /// </remarks>
  273. /// <param name="session">The session.</param>
  274. /// <param name="filter">The filter.</param>
  275. /// <param name="options">The options.</param>
  276. /// <param name="cancellationToken">The cancellation token.</param>
  277. /// <returns>
  278. /// The number of documents in the collection.
  279. /// </returns>
  280. Task<long> CountDocumentsAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  281. /// <summary>
  282. /// Deletes multiple documents.
  283. /// </summary>
  284. /// <param name="filter">The filter.</param>
  285. /// <param name="cancellationToken">The cancellation token.</param>
  286. /// <returns>
  287. /// The result of the delete operation.
  288. /// </returns>
  289. DeleteResult DeleteMany(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default(CancellationToken));
  290. /// <summary>
  291. /// Deletes multiple documents.
  292. /// </summary>
  293. /// <param name="filter">The filter.</param>
  294. /// <param name="options">The options.</param>
  295. /// <param name="cancellationToken">The cancellation token.</param>
  296. /// <returns>
  297. /// The result of the delete operation.
  298. /// </returns>
  299. DeleteResult DeleteMany(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
  300. /// <summary>
  301. /// Deletes multiple documents.
  302. /// </summary>
  303. /// <param name="session">The session.</param>
  304. /// <param name="filter">The filter.</param>
  305. /// <param name="options">The options.</param>
  306. /// <param name="cancellationToken">The cancellation token.</param>
  307. /// <returns>
  308. /// The result of the delete operation.
  309. /// </returns>
  310. DeleteResult DeleteMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  311. /// <summary>
  312. /// Deletes multiple documents.
  313. /// </summary>
  314. /// <param name="filter">The filter.</param>
  315. /// <param name="cancellationToken">The cancellation token.</param>
  316. /// <returns>
  317. /// The result of the delete operation.
  318. /// </returns>
  319. Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default(CancellationToken));
  320. /// <summary>
  321. /// Deletes multiple documents.
  322. /// </summary>
  323. /// <param name="filter">The filter.</param>
  324. /// <param name="options">The options.</param>
  325. /// <param name="cancellationToken">The cancellation token.</param>
  326. /// <returns>
  327. /// The result of the delete operation.
  328. /// </returns>
  329. Task<DeleteResult> DeleteManyAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
  330. /// <summary>
  331. /// Deletes multiple documents.
  332. /// </summary>
  333. /// <param name="session">The session.</param>
  334. /// <param name="filter">The filter.</param>
  335. /// <param name="options">The options.</param>
  336. /// <param name="cancellationToken">The cancellation token.</param>
  337. /// <returns>
  338. /// The result of the delete operation.
  339. /// </returns>
  340. Task<DeleteResult> DeleteManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  341. /// <summary>
  342. /// Deletes a single document.
  343. /// </summary>
  344. /// <param name="filter">The filter.</param>
  345. /// <param name="cancellationToken">The cancellation token.</param>
  346. /// <returns>
  347. /// The result of the delete operation.
  348. /// </returns>
  349. DeleteResult DeleteOne(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default(CancellationToken));
  350. /// <summary>
  351. /// Deletes a single document.
  352. /// </summary>
  353. /// <param name="filter">The filter.</param>
  354. /// <param name="options">The options.</param>
  355. /// <param name="cancellationToken">The cancellation token.</param>
  356. /// <returns>
  357. /// The result of the delete operation.
  358. /// </returns>
  359. DeleteResult DeleteOne(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
  360. /// <summary>
  361. /// Deletes a single document.
  362. /// </summary>
  363. /// <param name="session">The session.</param>
  364. /// <param name="filter">The filter.</param>
  365. /// <param name="options">The options.</param>
  366. /// <param name="cancellationToken">The cancellation token.</param>
  367. /// <returns>
  368. /// The result of the delete operation.
  369. /// </returns>
  370. DeleteResult DeleteOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  371. /// <summary>
  372. /// Deletes a single document.
  373. /// </summary>
  374. /// <param name="filter">The filter.</param>
  375. /// <param name="cancellationToken">The cancellation token.</param>
  376. /// <returns>
  377. /// The result of the delete operation.
  378. /// </returns>
  379. Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = default(CancellationToken));
  380. /// <summary>
  381. /// Deletes a single document.
  382. /// </summary>
  383. /// <param name="filter">The filter.</param>
  384. /// <param name="options">The options.</param>
  385. /// <param name="cancellationToken">The cancellation token.</param>
  386. /// <returns>
  387. /// The result of the delete operation.
  388. /// </returns>
  389. Task<DeleteResult> DeleteOneAsync(FilterDefinition<TDocument> filter, DeleteOptions options, CancellationToken cancellationToken = default(CancellationToken));
  390. /// <summary>
  391. /// Deletes a single document.
  392. /// </summary>
  393. /// <param name="session">The session.</param>
  394. /// <param name="filter">The filter.</param>
  395. /// <param name="options">The options.</param>
  396. /// <param name="cancellationToken">The cancellation token.</param>
  397. /// <returns>
  398. /// The result of the delete operation.
  399. /// </returns>
  400. Task<DeleteResult> DeleteOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, DeleteOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  401. /// <summary>
  402. /// Gets the distinct values for a specified field.
  403. /// </summary>
  404. /// <typeparam name="TField">The type of the result.</typeparam>
  405. /// <param name="field">The field.</param>
  406. /// <param name="filter">The filter.</param>
  407. /// <param name="options">The options.</param>
  408. /// <param name="cancellationToken">The cancellation token.</param>
  409. /// <returns>A cursor.</returns>
  410. IAsyncCursor<TField> Distinct<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  411. /// <summary>
  412. /// Gets the distinct values for a specified field.
  413. /// </summary>
  414. /// <typeparam name="TField">The type of the result.</typeparam>
  415. /// <param name="session">The session.</param>
  416. /// <param name="field">The field.</param>
  417. /// <param name="filter">The filter.</param>
  418. /// <param name="options">The options.</param>
  419. /// <param name="cancellationToken">The cancellation token.</param>
  420. /// <returns>
  421. /// A cursor.
  422. /// </returns>
  423. IAsyncCursor<TField> Distinct<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  424. /// <summary>
  425. /// Gets the distinct values for a specified field.
  426. /// </summary>
  427. /// <typeparam name="TField">The type of the result.</typeparam>
  428. /// <param name="field">The field.</param>
  429. /// <param name="filter">The filter.</param>
  430. /// <param name="options">The options.</param>
  431. /// <param name="cancellationToken">The cancellation token.</param>
  432. /// <returns>A Task whose result is a cursor.</returns>
  433. Task<IAsyncCursor<TField>> DistinctAsync<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  434. /// <summary>
  435. /// Gets the distinct values for a specified field.
  436. /// </summary>
  437. /// <typeparam name="TField">The type of the result.</typeparam>
  438. /// <param name="session">The session.</param>
  439. /// <param name="field">The field.</param>
  440. /// <param name="filter">The filter.</param>
  441. /// <param name="options">The options.</param>
  442. /// <param name="cancellationToken">The cancellation token.</param>
  443. /// <returns>
  444. /// A Task whose result is a cursor.
  445. /// </returns>
  446. Task<IAsyncCursor<TField>> DistinctAsync<TField>(IClientSessionHandle session, FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  447. /// <summary>
  448. /// Returns an estimate of the number of documents in the collection.
  449. /// </summary>
  450. /// <param name="options">The options.</param>
  451. /// <param name="cancellationToken">The cancellation token.</param>
  452. /// <returns>
  453. /// An estimate of the number of documents in the collection.
  454. /// </returns>
  455. long EstimatedDocumentCount(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  456. /// <summary>
  457. /// Returns an estimate of the number of documents in the collection.
  458. /// </summary>
  459. /// <param name="options">The options.</param>
  460. /// <param name="cancellationToken">The cancellation token.</param>
  461. /// <returns>
  462. /// An estimate of the number of documents in the collection.
  463. /// </returns>
  464. Task<long> EstimatedDocumentCountAsync(EstimatedDocumentCountOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  465. /// <summary>
  466. /// Finds the documents matching the filter.
  467. /// </summary>
  468. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  469. /// <param name="filter">The filter.</param>
  470. /// <param name="options">The options.</param>
  471. /// <param name="cancellationToken">The cancellation token.</param>
  472. /// <returns>A cursor.</returns>
  473. IAsyncCursor<TProjection> FindSync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  474. /// <summary>
  475. /// Finds the documents matching the filter.
  476. /// </summary>
  477. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  478. /// <param name="session">The session.</param>
  479. /// <param name="filter">The filter.</param>
  480. /// <param name="options">The options.</param>
  481. /// <param name="cancellationToken">The cancellation token.</param>
  482. /// <returns>
  483. /// A cursor.
  484. /// </returns>
  485. IAsyncCursor<TProjection> FindSync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  486. /// <summary>
  487. /// Finds the documents matching the filter.
  488. /// </summary>
  489. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  490. /// <param name="filter">The filter.</param>
  491. /// <param name="options">The options.</param>
  492. /// <param name="cancellationToken">The cancellation token.</param>
  493. /// <returns>A Task whose result is a cursor.</returns>
  494. Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  495. /// <summary>
  496. /// Finds the documents matching the filter.
  497. /// </summary>
  498. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  499. /// <param name="session">The session.</param>
  500. /// <param name="filter">The filter.</param>
  501. /// <param name="options">The options.</param>
  502. /// <param name="cancellationToken">The cancellation token.</param>
  503. /// <returns>
  504. /// A Task whose result is a cursor.
  505. /// </returns>
  506. Task<IAsyncCursor<TProjection>> FindAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  507. /// <summary>
  508. /// Finds a single document and deletes it atomically.
  509. /// </summary>
  510. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  511. /// <param name="filter">The filter.</param>
  512. /// <param name="options">The options.</param>
  513. /// <param name="cancellationToken">The cancellation token.</param>
  514. /// <returns>
  515. /// The returned document.
  516. /// </returns>
  517. TProjection FindOneAndDelete<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  518. /// <summary>
  519. /// Finds a single document and deletes it atomically.
  520. /// </summary>
  521. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  522. /// <param name="session">The session.</param>
  523. /// <param name="filter">The filter.</param>
  524. /// <param name="options">The options.</param>
  525. /// <param name="cancellationToken">The cancellation token.</param>
  526. /// <returns>
  527. /// The returned document.
  528. /// </returns>
  529. TProjection FindOneAndDelete<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  530. /// <summary>
  531. /// Finds a single document and deletes it atomically.
  532. /// </summary>
  533. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  534. /// <param name="filter">The filter.</param>
  535. /// <param name="options">The options.</param>
  536. /// <param name="cancellationToken">The cancellation token.</param>
  537. /// <returns>
  538. /// The returned document.
  539. /// </returns>
  540. Task<TProjection> FindOneAndDeleteAsync<TProjection>(FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  541. /// <summary>
  542. /// Finds a single document and deletes it atomically.
  543. /// </summary>
  544. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  545. /// <param name="session">The session.</param>
  546. /// <param name="filter">The filter.</param>
  547. /// <param name="options">The options.</param>
  548. /// <param name="cancellationToken">The cancellation token.</param>
  549. /// <returns>
  550. /// The returned document.
  551. /// </returns>
  552. Task<TProjection> FindOneAndDeleteAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, FindOneAndDeleteOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  553. /// <summary>
  554. /// Finds a single document and replaces it atomically.
  555. /// </summary>
  556. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  557. /// <param name="filter">The filter.</param>
  558. /// <param name="replacement">The replacement.</param>
  559. /// <param name="options">The options.</param>
  560. /// <param name="cancellationToken">The cancellation token.</param>
  561. /// <returns>
  562. /// The returned document.
  563. /// </returns>
  564. TProjection FindOneAndReplace<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  565. /// <summary>
  566. /// Finds a single document and replaces it atomically.
  567. /// </summary>
  568. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  569. /// <param name="session">The session.</param>
  570. /// <param name="filter">The filter.</param>
  571. /// <param name="replacement">The replacement.</param>
  572. /// <param name="options">The options.</param>
  573. /// <param name="cancellationToken">The cancellation token.</param>
  574. /// <returns>
  575. /// The returned document.
  576. /// </returns>
  577. TProjection FindOneAndReplace<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  578. /// <summary>
  579. /// Finds a single document and replaces it atomically.
  580. /// </summary>
  581. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  582. /// <param name="filter">The filter.</param>
  583. /// <param name="replacement">The replacement.</param>
  584. /// <param name="options">The options.</param>
  585. /// <param name="cancellationToken">The cancellation token.</param>
  586. /// <returns>
  587. /// The returned document.
  588. /// </returns>
  589. Task<TProjection> FindOneAndReplaceAsync<TProjection>(FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  590. /// <summary>
  591. /// Finds a single document and replaces it atomically.
  592. /// </summary>
  593. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  594. /// <param name="session">The session.</param>
  595. /// <param name="filter">The filter.</param>
  596. /// <param name="replacement">The replacement.</param>
  597. /// <param name="options">The options.</param>
  598. /// <param name="cancellationToken">The cancellation token.</param>
  599. /// <returns>
  600. /// The returned document.
  601. /// </returns>
  602. Task<TProjection> FindOneAndReplaceAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  603. /// <summary>
  604. /// Finds a single document and updates it atomically.
  605. /// </summary>
  606. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  607. /// <param name="filter">The filter.</param>
  608. /// <param name="update">The update.</param>
  609. /// <param name="options">The options.</param>
  610. /// <param name="cancellationToken">The cancellation token.</param>
  611. /// <returns>
  612. /// The returned document.
  613. /// </returns>
  614. TProjection FindOneAndUpdate<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  615. /// <summary>
  616. /// Finds a single document and updates it atomically.
  617. /// </summary>
  618. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  619. /// <param name="session">The session.</param>
  620. /// <param name="filter">The filter.</param>
  621. /// <param name="update">The update.</param>
  622. /// <param name="options">The options.</param>
  623. /// <param name="cancellationToken">The cancellation token.</param>
  624. /// <returns>
  625. /// The returned document.
  626. /// </returns>
  627. TProjection FindOneAndUpdate<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  628. /// <summary>
  629. /// Finds a single document and updates it atomically.
  630. /// </summary>
  631. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  632. /// <param name="filter">The filter.</param>
  633. /// <param name="update">The update.</param>
  634. /// <param name="options">The options.</param>
  635. /// <param name="cancellationToken">The cancellation token.</param>
  636. /// <returns>
  637. /// The returned document.
  638. /// </returns>
  639. Task<TProjection> FindOneAndUpdateAsync<TProjection>(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  640. /// <summary>
  641. /// Finds a single document and updates it atomically.
  642. /// </summary>
  643. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  644. /// <param name="session">The session.</param>
  645. /// <param name="filter">The filter.</param>
  646. /// <param name="update">The update.</param>
  647. /// <param name="options">The options.</param>
  648. /// <param name="cancellationToken">The cancellation token.</param>
  649. /// <returns>
  650. /// The returned document.
  651. /// </returns>
  652. Task<TProjection> FindOneAndUpdateAsync<TProjection>(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
  653. /// <summary>
  654. /// Inserts a single document.
  655. /// </summary>
  656. /// <param name="document">The document.</param>
  657. /// <param name="options">The options.</param>
  658. /// <param name="cancellationToken">The cancellation token.</param>
  659. void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  660. /// <summary>
  661. /// Inserts a single document.
  662. /// </summary>
  663. /// <param name="session">The session.</param>
  664. /// <param name="document">The document.</param>
  665. /// <param name="options">The options.</param>
  666. /// <param name="cancellationToken">The cancellation token.</param>
  667. void InsertOne( IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  668. /// <summary>
  669. /// Inserts a single document.
  670. /// </summary>
  671. /// <param name="document">The document.</param>
  672. /// <param name="_cancellationToken">The cancellation token.</param>
  673. /// <returns>
  674. /// The result of the insert operation.
  675. /// </returns>
  676. [Obsolete("Use the new overload of InsertOneAsync with an InsertOneOptions parameter instead.")]
  677. Task InsertOneAsync(TDocument document, CancellationToken _cancellationToken);
  678. /// <summary>
  679. /// Inserts a single document.
  680. /// </summary>
  681. /// <param name="document">The document.</param>
  682. /// <param name="options">The options.</param>
  683. /// <param name="cancellationToken">The cancellation token.</param>
  684. /// <returns>
  685. /// The result of the insert operation.
  686. /// </returns>
  687. Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  688. /// <summary>
  689. /// Inserts a single document.
  690. /// </summary>
  691. /// <param name="session">The session.</param>
  692. /// <param name="document">The document.</param>
  693. /// <param name="options">The options.</param>
  694. /// <param name="cancellationToken">The cancellation token.</param>
  695. /// <returns>
  696. /// The result of the insert operation.
  697. /// </returns>
  698. Task InsertOneAsync(IClientSessionHandle session, TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  699. /// <summary>
  700. /// Inserts many documents.
  701. /// </summary>
  702. /// <param name="documents">The documents.</param>
  703. /// <param name="options">The options.</param>
  704. /// <param name="cancellationToken">The cancellation token.</param>
  705. void InsertMany(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  706. /// <summary>
  707. /// Inserts many documents.
  708. /// </summary>
  709. /// <param name="session">The session.</param>
  710. /// <param name="documents">The documents.</param>
  711. /// <param name="options">The options.</param>
  712. /// <param name="cancellationToken">The cancellation token.</param>
  713. void InsertMany(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  714. /// <summary>
  715. /// Inserts many documents.
  716. /// </summary>
  717. /// <param name="documents">The documents.</param>
  718. /// <param name="options">The options.</param>
  719. /// <param name="cancellationToken">The cancellation token.</param>
  720. /// <returns>
  721. /// The result of the insert operation.
  722. /// </returns>
  723. Task InsertManyAsync(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  724. /// <summary>
  725. /// Inserts many documents.
  726. /// </summary>
  727. /// <param name="session">The session.</param>
  728. /// <param name="documents">The documents.</param>
  729. /// <param name="options">The options.</param>
  730. /// <param name="cancellationToken">The cancellation token.</param>
  731. /// <returns>
  732. /// The result of the insert operation.
  733. /// </returns>
  734. Task InsertManyAsync(IClientSessionHandle session, IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  735. /// <summary>
  736. /// Executes a map-reduce command.
  737. /// </summary>
  738. /// <typeparam name="TResult">The type of the result.</typeparam>
  739. /// <param name="map">The map function.</param>
  740. /// <param name="reduce">The reduce function.</param>
  741. /// <param name="options">The options.</param>
  742. /// <param name="cancellationToken">The cancellation token.</param>
  743. /// <returns>A cursor.</returns>
  744. IAsyncCursor<TResult> MapReduce<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken));
  745. /// <summary>
  746. /// Executes a map-reduce command.
  747. /// </summary>
  748. /// <typeparam name="TResult">The type of the result.</typeparam>
  749. /// <param name="session">The session.</param>
  750. /// <param name="map">The map function.</param>
  751. /// <param name="reduce">The reduce function.</param>
  752. /// <param name="options">The options.</param>
  753. /// <param name="cancellationToken">The cancellation token.</param>
  754. /// <returns>
  755. /// A cursor.
  756. /// </returns>
  757. IAsyncCursor<TResult> MapReduce<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken));
  758. /// <summary>
  759. /// Executes a map-reduce command.
  760. /// </summary>
  761. /// <typeparam name="TResult">The type of the result.</typeparam>
  762. /// <param name="map">The map function.</param>
  763. /// <param name="reduce">The reduce function.</param>
  764. /// <param name="options">The options.</param>
  765. /// <param name="cancellationToken">The cancellation token.</param>
  766. /// <returns>A Task whose result is a cursor.</returns>
  767. Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken));
  768. /// <summary>
  769. /// Executes a map-reduce command.
  770. /// </summary>
  771. /// <typeparam name="TResult">The type of the result.</typeparam>
  772. /// <param name="session">The session.</param>
  773. /// <param name="map">The map function.</param>
  774. /// <param name="reduce">The reduce function.</param>
  775. /// <param name="options">The options.</param>
  776. /// <param name="cancellationToken">The cancellation token.</param>
  777. /// <returns>
  778. /// A Task whose result is a cursor.
  779. /// </returns>
  780. Task<IAsyncCursor<TResult>> MapReduceAsync<TResult>(IClientSessionHandle session, BsonJavaScript map, BsonJavaScript reduce, MapReduceOptions<TDocument, TResult> options = null, CancellationToken cancellationToken = default(CancellationToken));
  781. /// <summary>
  782. /// Returns a filtered collection that appears to contain only documents of the derived type.
  783. /// All operations using this filtered collection will automatically use discriminators as necessary.
  784. /// </summary>
  785. /// <typeparam name="TDerivedDocument">The type of the derived document.</typeparam>
  786. /// <returns>A filtered collection.</returns>
  787. IFilteredMongoCollection<TDerivedDocument> OfType<TDerivedDocument>() where TDerivedDocument : TDocument;
  788. /// <summary>
  789. /// Replaces a single document.
  790. /// </summary>
  791. /// <param name="filter">The filter.</param>
  792. /// <param name="replacement">The replacement.</param>
  793. /// <param name="options">The options.</param>
  794. /// <param name="cancellationToken">The cancellation token.</param>
  795. /// <returns>
  796. /// The result of the replacement.
  797. /// </returns>
  798. ReplaceOneResult ReplaceOne(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  799. /// <summary>
  800. /// Replaces a single document.
  801. /// </summary>
  802. /// <param name="session">The session.</param>
  803. /// <param name="filter">The filter.</param>
  804. /// <param name="replacement">The replacement.</param>
  805. /// <param name="options">The options.</param>
  806. /// <param name="cancellationToken">The cancellation token.</param>
  807. /// <returns>
  808. /// The result of the replacement.
  809. /// </returns>
  810. ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  811. /// <summary>
  812. /// Replaces a single document.
  813. /// </summary>
  814. /// <param name="filter">The filter.</param>
  815. /// <param name="replacement">The replacement.</param>
  816. /// <param name="options">The options.</param>
  817. /// <param name="cancellationToken">The cancellation token.</param>
  818. /// <returns>
  819. /// The result of the replacement.
  820. /// </returns>
  821. Task<ReplaceOneResult> ReplaceOneAsync(FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  822. /// <summary>
  823. /// Replaces a single document.
  824. /// </summary>
  825. /// <param name="session">The session.</param>
  826. /// <param name="filter">The filter.</param>
  827. /// <param name="replacement">The replacement.</param>
  828. /// <param name="options">The options.</param>
  829. /// <param name="cancellationToken">The cancellation token.</param>
  830. /// <returns>
  831. /// The result of the replacement.
  832. /// </returns>
  833. Task<ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  834. /// <summary>
  835. /// Updates many documents.
  836. /// </summary>
  837. /// <param name="filter">The filter.</param>
  838. /// <param name="update">The update.</param>
  839. /// <param name="options">The options.</param>
  840. /// <param name="cancellationToken">The cancellation token.</param>
  841. /// <returns>
  842. /// The result of the update operation.
  843. /// </returns>
  844. UpdateResult UpdateMany(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  845. /// <summary>
  846. /// Updates many documents.
  847. /// </summary>
  848. /// <param name="session">The session.</param>
  849. /// <param name="filter">The filter.</param>
  850. /// <param name="update">The update.</param>
  851. /// <param name="options">The options.</param>
  852. /// <param name="cancellationToken">The cancellation token.</param>
  853. /// <returns>
  854. /// The result of the update operation.
  855. /// </returns>
  856. UpdateResult UpdateMany(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  857. /// <summary>
  858. /// Updates many documents.
  859. /// </summary>
  860. /// <param name="filter">The filter.</param>
  861. /// <param name="update">The update.</param>
  862. /// <param name="options">The options.</param>
  863. /// <param name="cancellationToken">The cancellation token.</param>
  864. /// <returns>
  865. /// The result of the update operation.
  866. /// </returns>
  867. Task<UpdateResult> UpdateManyAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  868. /// <summary>
  869. /// Updates many documents.
  870. /// </summary>
  871. /// <param name="session">The session.</param>
  872. /// <param name="filter">The filter.</param>
  873. /// <param name="update">The update.</param>
  874. /// <param name="options">The options.</param>
  875. /// <param name="cancellationToken">The cancellation token.</param>
  876. /// <returns>
  877. /// The result of the update operation.
  878. /// </returns>
  879. Task<UpdateResult> UpdateManyAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  880. /// <summary>
  881. /// Updates a single document.
  882. /// </summary>
  883. /// <param name="filter">The filter.</param>
  884. /// <param name="update">The update.</param>
  885. /// <param name="options">The options.</param>
  886. /// <param name="cancellationToken">The cancellation token.</param>
  887. /// <returns>
  888. /// The result of the update operation.
  889. /// </returns>
  890. UpdateResult UpdateOne(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  891. /// <summary>
  892. /// Updates a single document.
  893. /// </summary>
  894. /// <param name="session">The session.</param>
  895. /// <param name="filter">The filter.</param>
  896. /// <param name="update">The update.</param>
  897. /// <param name="options">The options.</param>
  898. /// <param name="cancellationToken">The cancellation token.</param>
  899. /// <returns>
  900. /// The result of the update operation.
  901. /// </returns>
  902. UpdateResult UpdateOne(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  903. /// <summary>
  904. /// Updates a single document.
  905. /// </summary>
  906. /// <param name="filter">The filter.</param>
  907. /// <param name="update">The update.</param>
  908. /// <param name="options">The options.</param>
  909. /// <param name="cancellationToken">The cancellation token.</param>
  910. /// <returns>
  911. /// The result of the update operation.
  912. /// </returns>
  913. Task<UpdateResult> UpdateOneAsync(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  914. /// <summary>
  915. /// Updates a single document.
  916. /// </summary>
  917. /// <param name="session">The session.</param>
  918. /// <param name="filter">The filter.</param>
  919. /// <param name="update">The update.</param>
  920. /// <param name="options">The options.</param>
  921. /// <param name="cancellationToken">The cancellation token.</param>
  922. /// <returns>
  923. /// The result of the update operation.
  924. /// </returns>
  925. Task<UpdateResult> UpdateOneAsync(IClientSessionHandle session, FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
  926. /// <summary>
  927. /// Watches changes on the collection.
  928. /// </summary>
  929. /// <typeparam name="TResult">The type of the result.</typeparam>
  930. /// <param name="pipeline">The pipeline.</param>
  931. /// <param name="options">The options.</param>
  932. /// <param name="cancellationToken">The cancellation token.</param>
  933. /// <returns>
  934. /// A change stream.
  935. /// </returns>
  936. IAsyncCursor<TResult> Watch<TResult>(
  937. PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline,
  938. ChangeStreamOptions options = null,
  939. CancellationToken cancellationToken = default(CancellationToken));
  940. /// <summary>
  941. /// Watches changes on the collection.
  942. /// </summary>
  943. /// <typeparam name="TResult">The type of the result.</typeparam>
  944. /// <param name="session">The session.</param>
  945. /// <param name="pipeline">The pipeline.</param>
  946. /// <param name="options">The options.</param>
  947. /// <param name="cancellationToken">The cancellation token.</param>
  948. /// <returns>
  949. /// A change stream.
  950. /// </returns>
  951. IAsyncCursor<TResult> Watch<TResult>(
  952. IClientSessionHandle session,
  953. PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline,
  954. ChangeStreamOptions options = null,
  955. CancellationToken cancellationToken = default(CancellationToken));
  956. /// <summary>
  957. /// Watches changes on the collection.
  958. /// </summary>
  959. /// <typeparam name="TResult">The type of the result.</typeparam>
  960. /// <param name="pipeline">The pipeline.</param>
  961. /// <param name="options">The options.</param>
  962. /// <param name="cancellationToken">The cancellation token.</param>
  963. /// <returns>
  964. /// A change stream.
  965. /// </returns>
  966. Task<IAsyncCursor<TResult>> WatchAsync<TResult>(
  967. PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline,
  968. ChangeStreamOptions options = null,
  969. CancellationToken cancellationToken = default(CancellationToken));
  970. /// <summary>
  971. /// Watches changes on the collection.
  972. /// </summary>
  973. /// <typeparam name="TResult">The type of the result.</typeparam>
  974. /// <param name="session">The session.</param>
  975. /// <param name="pipeline">The pipeline.</param>
  976. /// <param name="options">The options.</param>
  977. /// <param name="cancellationToken">The cancellation token.</param>
  978. /// <returns>
  979. /// A change stream.
  980. /// </returns>
  981. Task<IAsyncCursor<TResult>> WatchAsync<TResult>(
  982. IClientSessionHandle session,
  983. PipelineDefinition<ChangeStreamDocument<TDocument>, TResult> pipeline,
  984. ChangeStreamOptions options = null,
  985. CancellationToken cancellationToken = default(CancellationToken));
  986. /// <summary>
  987. /// Returns a new IMongoCollection instance with a different read concern setting.
  988. /// </summary>
  989. /// <param name="readConcern">The read concern.</param>
  990. /// <returns>A new IMongoCollection instance with a different read concern setting.</returns>
  991. IMongoCollection<TDocument> WithReadConcern(ReadConcern readConcern);
  992. /// <summary>
  993. /// Returns a new IMongoCollection instance with a different read preference setting.
  994. /// </summary>
  995. /// <param name="readPreference">The read preference.</param>
  996. /// <returns>A new IMongoCollection instance with a different read preference setting.</returns>
  997. IMongoCollection<TDocument> WithReadPreference(ReadPreference readPreference);
  998. /// <summary>
  999. /// Returns a new IMongoCollection instance with a different write concern setting.
  1000. /// </summary>
  1001. /// <param name="writeConcern">The write concern.</param>
  1002. /// <returns>A new IMongoCollection instance with a different write concern setting.</returns>
  1003. IMongoCollection<TDocument> WithWriteConcern(WriteConcern writeConcern);
  1004. }
  1005. }