Method Single

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

Namespace

MongoDB.Driver

Assembly

MongoDB.Driver.dll

Single(IAsyncCursor, CancellationToken)

Returns the only document of a cursor. This method throws an exception if the cursor does not contain exactly one document.

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

Parameters

cursor IAsyncCursor

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The only document of a cursor.

Type Parameters

TDocument

The type of the document.