Table of Contents

Method FirstAsync

Namespace
MongoDB.Driver.Linq
Assembly
MongoDB.Driver.dll

FirstAsync<TSource>(IMongoQueryable<TSource>, CancellationToken)

Returns the first element of a sequence.

public static Task<TSource> FirstAsync<TSource>(this IMongoQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IMongoQueryable<TSource>

The IMongoQueryable<T> to return the first element of.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TSource>

The first element in source.

Type Parameters

TSource

The type of the elements of source.

FirstAsync<TSource>(IMongoQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Returns the first element of a sequence that satisfies a specified condition.

public static Task<TSource> FirstAsync<TSource>(this IMongoQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

Parameters

source IMongoQueryable<TSource>

An IMongoQueryable<T> to return an element from.

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TSource>

The first element in source that passes the test in predicate.

Type Parameters

TSource

The type of the elements of source.