Method SingleOrDefault
SingleOrDefault<TDocument>(IAsyncCursorSource<TDocument>, CancellationToken)
Returns the only document of a cursor returned by a cursor source, 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 TDocument SingleOrDefault<TDocument>(this IAsyncCursorSource<TDocument> source, CancellationToken cancellationToken = default)
Parameters
sourceIAsyncCursorSource<TDocument>The source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- TDocument
The only document of a cursor, or a default value if the cursor contains no documents.
Type Parameters
TDocumentThe type of the document.