Table of Contents

Class IAsyncCursorExtensions

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

Represents extension methods for IAsyncCursor.

public static class IAsyncCursorExtensions
Inheritance
IAsyncCursorExtensions
Inherited Members

Methods

AnyAsync<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Determines whether the cursor contains any documents.

public static Task<bool> AnyAsync<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<bool>

A Task whose result is true if the cursor contains any documents.

Type Parameters

TDocument

The type of the document.

Any<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Determines whether the cursor contains any documents.

public static bool Any<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

bool

True if the cursor contains any documents.

Type Parameters

TDocument

The type of the document.

FirstAsync<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Returns the first document of a cursor.

public static Task<TDocument> FirstAsync<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

A Task whose result is the first document.

Type Parameters

TDocument

The type of the document.

FirstOrDefaultAsync<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Returns the first document of the cursor, or a default value if the cursor contains no documents.

public static Task<TDocument> FirstOrDefaultAsync<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TDocument>

A task whose result is the first document of the cursor, or a default value if the cursor contains no documents.

Type Parameters

TDocument

The type of the document.

FirstOrDefault<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Returns the first document of a cursor, or a default value if the cursor contains no documents.

public static TDocument FirstOrDefault<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The first document of the cursor, or a default value if the cursor contains no documents.

Type Parameters

TDocument

The type of the document.

First<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Returns the first document of a cursor.

public static TDocument First<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The first document.

Type Parameters

TDocument

The type of the document.

ForEachAsync<TDocument>(IAsyncCursor<TDocument>, Action<TDocument, int>, CancellationToken)

Calls a delegate for each document returned by the cursor.

public static Task ForEachAsync<TDocument>(this IAsyncCursor<TDocument> source, Action<TDocument, int> processor, CancellationToken cancellationToken = default)

Parameters

source IAsyncCursor<TDocument>

The source.

processor Action<TDocument, int>

The processor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task that completes when all the documents have been processed.

Type Parameters

TDocument

The type of the document.

Remarks

If your delegate is going to take a long time to execute or is going to block consider using a different overload of ForEachAsync that uses a delegate that returns a Task instead.

ForEachAsync<TDocument>(IAsyncCursor<TDocument>, Action<TDocument>, CancellationToken)

Calls a delegate for each document returned by the cursor.

public static Task ForEachAsync<TDocument>(this IAsyncCursor<TDocument> source, Action<TDocument> processor, CancellationToken cancellationToken = default)

Parameters

source IAsyncCursor<TDocument>

The source.

processor Action<TDocument>

The processor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task that completes when all the documents have been processed.

Type Parameters

TDocument

The type of the document.

Remarks

If your delegate is going to take a long time to execute or is going to block consider using a different overload of ForEachAsync that uses a delegate that returns a Task instead.

ForEachAsync<TDocument>(IAsyncCursor<TDocument>, Func<TDocument, int, Task>, CancellationToken)

Calls a delegate for each document returned by the cursor.

public static Task ForEachAsync<TDocument>(this IAsyncCursor<TDocument> source, Func<TDocument, int, Task> processor, CancellationToken cancellationToken = default)

Parameters

source IAsyncCursor<TDocument>

The source.

processor Func<TDocument, int, Task>

The processor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task that completes when all the documents have been processed.

Type Parameters

TDocument

The type of the document.

ForEachAsync<TDocument>(IAsyncCursor<TDocument>, Func<TDocument, Task>, CancellationToken)

Calls a delegate for each document returned by the cursor.

public static Task ForEachAsync<TDocument>(this IAsyncCursor<TDocument> source, Func<TDocument, Task> processor, CancellationToken cancellationToken = default)

Parameters

source IAsyncCursor<TDocument>

The source.

processor Func<TDocument, Task>

The processor.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A Task that completes when all the documents have been processed.

Type Parameters

TDocument

The type of the document.

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

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

public static Task<TDocument> SingleAsync<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

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.

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

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The 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

TDocument

The type of the document.

SingleOrDefault<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 TDocument SingleOrDefault<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The only document of a cursor, or a default value if the cursor contains no documents.

Type Parameters

TDocument

The type of the document.

Single<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

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

public static TDocument Single<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

TDocument

The only document of a cursor.

Type Parameters

TDocument

The type of the document.

ToEnumerable<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Wraps a cursor in an IEnumerable that can be enumerated one time.

public static IEnumerable<TDocument> ToEnumerable<TDocument>(this IAsyncCursor<TDocument> cursor, CancellationToken cancellationToken = default)

Parameters

cursor IAsyncCursor<TDocument>

The cursor.

cancellationToken CancellationToken

The cancellation token.

Returns

IEnumerable<TDocument>

An IEnumerable

Type Parameters

TDocument

The type of the document.

ToListAsync<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Returns a list containing all the documents returned by a cursor.

public static Task<List<TDocument>> ToListAsync<TDocument>(this IAsyncCursor<TDocument> source, CancellationToken cancellationToken = default)

Parameters

source IAsyncCursor<TDocument>

The source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<List<TDocument>>

A Task whose value is the list of documents.

Type Parameters

TDocument

The type of the document.

ToList<TDocument>(IAsyncCursor<TDocument>, CancellationToken)

Returns a list containing all the documents returned by a cursor.

public static List<TDocument> ToList<TDocument>(this IAsyncCursor<TDocument> source, CancellationToken cancellationToken = default)

Parameters

source IAsyncCursor<TDocument>

The source.

cancellationToken CancellationToken

The cancellation token.

Returns

List<TDocument>

The list of documents.

Type Parameters

TDocument

The type of the document.