Table of Contents

Method SingleAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

SingleAsync<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

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

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

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

A Task whose result is the only document of a cursor.

Type Parameters

TDocument

The type of the document.