Table of Contents

Method SingleOrDefaultAsync

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.dll

SingleOrDefaultAsync<TResult>(IAggregateFluent<TResult>, CancellationToken)

Returns the only document of the aggregate result, or the default value if the result set is empty. Throws an exception if the result set contains more than one document.

public static Task<TResult> SingleOrDefaultAsync<TResult>(this IAggregateFluent<TResult> aggregate, CancellationToken cancellationToken = default)

Parameters

aggregate IAggregateFluent<TResult>

The aggregate.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TResult>

The fluent aggregate interface.

Type Parameters

TResult

The type of the result.