Table of Contents

Class CollectionFindCursor<T, TResult>

Namespace
DataStax.AstraDB.DataApi.Core.Enumeration
Assembly
DataStax.AstraDB.DataApi.dll

A cursor for finding and enumerating documents in a collection with projection support. This class allows you to specify a different result type than the document type, useful for projections.

public class CollectionFindCursor<T, TResult> : FindCursor<T, TResult, CollectionSortBuilder<T>, CollectionFindCursor<T, TResult>>, IDisposable, IEnumerable<TResult>, IEnumerable, IAsyncEnumerable<TResult> where T : class where TResult : class

Type Parameters

T

The type of the documents in the collection.

TResult

The type to deserialize the results to (e.g., when using projections).

Inheritance
CollectionFindCursor<T, TResult>
Implements
IEnumerable<TResult>
Derived
Inherited Members

Examples

// Using projection to return only specific fields
public class MyDocumentProjection
{
    public string Name { get; set; }
    public string Email { get; set; }
}

var cursor = collection.Find<MyDocumentProjection>()
    .Project(Builders<MyDocument>.Projection
        .Include(d => d.Name)
        .Include(d => d.Email))
    .Limit(100);

var results = await cursor.ToListAsync();

Remarks

This cursor is returned by Find<TResult>(CollectionFilter<T>, CollectionFindOptions<T>) and provides a fluent API for filtering, sorting, limiting, and projecting documents into a different result type.

Methods

Clone()

Creates a new cursor instance with the same configuration.

public override CollectionFindCursor<T, TResult> Clone()

Returns

CollectionFindCursor<T, TResult>

A new cursor instance.

CloneWith(Filter<T>, BaseFindOptions<T, CollectionSortBuilder<T>>)

Creates a new cursor instance with updated filter and options.

protected override CollectionFindCursor<T, TResult> CloneWith(Filter<T> filter, BaseFindOptions<T, CollectionSortBuilder<T>> options)

Parameters

filter Filter<T>

The filter to apply.

options BaseFindOptions<T, CollectionSortBuilder<T>>

The find options to use.

Returns

CollectionFindCursor<T, TResult>

A new cursor instance.