Method FirstOrDefault

| MongoDB CSharp Driver API Reference (original) (raw)

Namespace

MongoDB.Driver

Assembly

MongoDB.Driver.dll

FirstOrDefault(IAsyncCursor, CancellationToken)

Returns the first document of a cursor, or a default value if the cursor contains no documents.

public static TDocument FirstOrDefault<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The first document of the cursor, or a default value if the cursor contains no documents.

Type Parameters

TDocument

The type of the document.