Skip to main content

Distinct

The Limit method operates on the IFindFluent interface. It limits the number of documents to query from the database.

warning

Results must not be larger than the maximum BSON size (16 MB). If your results exceed the maximum BSON size, use the aggregation pipeline to retrieve distinct values using the $group operator, as described in Retrieve Distinct Values with the Aggregation Pipeline.

Syntax

IAsyncCursor<TField> Distinct<TField>(
FieldDefinition<TDocument, TField> field,
FilterDefinition<TDocument> filter,
DistinctOptions options = null,
CancellationToken cancellationToken = null
)

Parameters

field - FieldDefinition<TDocument, TField>

The field of the document to operate on.

filter - FilterDefinition<TDocument>

The filter to apply to the documents. Same as with the Find method.

options - DistinctOptions (optional)

Options to apply to the Distinct operation.

cancellationToken - CancellationToken (optional)

A cancellation token can be provided to the operation to cancel it prematurely.

Returns

IAsyncCursor<TField>

TODO

DistinctOptions

TODO

Example

_myCollection.Distinct(document => document.Name, _ => true);