Method SingleOrDefaultAsync
SingleOrDefaultAsync<TDocument>(IAsyncCursor<TDocument>, CancellationToken)
Returns the only document of a cursor, or a default value if the cursor contains no documents. This method throws an exception if the cursor contains more than one document.
public static Task<TDocument> SingleOrDefaultAsync<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)
Parameters
cursorIAsyncCursor<TDocument>The cursor.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TDocument>
A Task whose result is the only document of a cursor, or a default value if the cursor contains no documents.
Type Parameters
TDocumentThe type of the document.