IFindFluent.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.Threading;
  17. using System.Threading.Tasks;
  18. using MongoDB.Bson.Serialization;
  19. namespace MongoDB.Driver
  20. {
  21. /// <summary>
  22. /// Fluent interface for find.
  23. /// </summary>
  24. /// <remarks>
  25. /// This interface is not guaranteed to remain stable. Implementors should use
  26. /// <see cref="FindFluentBase{TDocument, TProjection}" />.
  27. /// </remarks>
  28. /// <typeparam name="TDocument">The type of the document.</typeparam>
  29. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  30. public interface IFindFluent<TDocument, TProjection> : IAsyncCursorSource<TProjection>
  31. {
  32. /// <summary>
  33. /// Gets or sets the filter.
  34. /// </summary>
  35. FilterDefinition<TDocument> Filter { get; set; }
  36. /// <summary>
  37. /// Gets the options.
  38. /// </summary>
  39. FindOptions<TDocument, TProjection> Options { get; }
  40. /// <summary>
  41. /// A simplified type of projection that changes the result type by using a different serializer.
  42. /// </summary>
  43. /// <typeparam name="TResult">The type of the result.</typeparam>
  44. /// <param name="resultSerializer">The result serializer.</param>
  45. /// <returns>The fluent find interface.</returns>
  46. IFindFluent<TDocument, TResult> As<TResult>(IBsonSerializer<TResult> resultSerializer = null);
  47. /// <summary>
  48. /// Counts the number of documents.
  49. /// </summary>
  50. /// <param name="cancellationToken">The cancellation token.</param>
  51. /// <returns>The count.</returns>
  52. [Obsolete("Use CountDocuments instead.")]
  53. long Count(CancellationToken cancellationToken = default(CancellationToken));
  54. /// <summary>
  55. /// Counts the number of documents.
  56. /// </summary>
  57. /// <param name="cancellationToken">The cancellation token.</param>
  58. /// <returns>A Task whose result is the count.</returns>
  59. [Obsolete("Use CountDocumentsAsync instead.")]
  60. Task<long> CountAsync(CancellationToken cancellationToken = default(CancellationToken));
  61. /// <summary>
  62. /// Counts the number of documents.
  63. /// </summary>
  64. /// <remarks>
  65. /// Note: when migrating from Count to CountDocuments the following query operations must be replaced:
  66. ///
  67. /// <code>
  68. /// +-------------+--------------------------------+
  69. /// | Operator | Replacement |
  70. /// +=============+================================+
  71. /// | $where | $expr |
  72. /// +-------------+--------------------------------+
  73. /// | $near | $geoWithin with $center |
  74. /// +-------------+--------------------------------+
  75. /// | $nearSphere | $geoWithin with $centerSphere |
  76. /// +-------------+--------------------------------+
  77. /// </code>
  78. /// </remarks>
  79. /// <param name="cancellationToken">The cancellation token.</param>
  80. /// <returns>The count.</returns>
  81. long CountDocuments(CancellationToken cancellationToken = default(CancellationToken));
  82. /// <summary>
  83. /// Counts the number of documents.
  84. /// </summary>
  85. /// <remarks>
  86. /// Note: when migrating from CountAsync to CountDocumentsAsync the following query operations must be replaced:
  87. ///
  88. /// <code>
  89. /// +-------------+--------------------------------+
  90. /// | Operator | Replacement |
  91. /// +=============+================================+
  92. /// | $where | $expr |
  93. /// +-------------+--------------------------------+
  94. /// | $near | $geoWithin with $center |
  95. /// +-------------+--------------------------------+
  96. /// | $nearSphere | $geoWithin with $centerSphere |
  97. /// +-------------+--------------------------------+
  98. /// </code>
  99. /// </remarks>
  100. /// <param name="cancellationToken">The cancellation token.</param>
  101. /// <returns>A Task whose result is the count.</returns>
  102. Task<long> CountDocumentsAsync(CancellationToken cancellationToken = default(CancellationToken));
  103. /// <summary>
  104. /// Limits the number of documents.
  105. /// </summary>
  106. /// <param name="limit">The limit.</param>
  107. /// <returns>The fluent find interface.</returns>
  108. IFindFluent<TDocument, TProjection> Limit(int? limit);
  109. /// <summary>
  110. /// Projects the the result.
  111. /// </summary>
  112. /// <typeparam name="TNewProjection">The type of the projection.</typeparam>
  113. /// <param name="projection">The projection.</param>
  114. /// <returns>The fluent find interface.</returns>
  115. IFindFluent<TDocument, TNewProjection> Project<TNewProjection>(ProjectionDefinition<TDocument, TNewProjection> projection);
  116. /// <summary>
  117. /// Skips the the specified number of documents.
  118. /// </summary>
  119. /// <param name="skip">The skip.</param>
  120. /// <returns>The fluent find interface.</returns>
  121. IFindFluent<TDocument, TProjection> Skip(int? skip);
  122. /// <summary>
  123. /// Sorts the the documents.
  124. /// </summary>
  125. /// <param name="sort">The sort.</param>
  126. /// <returns>The fluent find interface.</returns>
  127. IFindFluent<TDocument, TProjection> Sort(SortDefinition<TDocument> sort);
  128. }
  129. /// <summary>
  130. /// Fluent interface for find.
  131. /// </summary>
  132. /// <typeparam name="TDocument">The type of the document.</typeparam>
  133. /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
  134. public interface IOrderedFindFluent<TDocument, TProjection> : IFindFluent<TDocument, TProjection>
  135. {
  136. }
  137. }