/// <summary> /// Get the first result. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam> /// <param name="find">The fluent find.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A Task whose result is the first result.</returns> public static Task <TProjection> FirstAsync <TDocument, TProjection>(this IFindFluent <TDocument, TProjection> find, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(find, nameof(find)); return(IAsyncCursorSourceExtensions.FirstAsync(find.Limit(1), cancellationToken)); }
/// <summary> /// Returns the first document of the aggregate result. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="aggregate">The aggregate.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The fluent aggregate interface. /// </returns> public static Task <TResult> FirstAsync <TResult>(this IAggregateFluent <TResult> aggregate, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(aggregate, nameof(aggregate)); return(IAsyncCursorSourceExtensions.FirstAsync(aggregate.Limit(1), cancellationToken)); }