Table of Contents

Method SingleAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.Core.dll

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

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

public static Task<TDocument> SingleAsync<TDocument>(this IAsyncCursorSource<TDocument> source, CancellationToken cancellationToken = default)

Parameters

source IAsyncCursorSource<TDocument>

The source.

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.