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
TThe type of the documents in the collection.
TResultThe type to deserialize the results to (e.g., when using projections).
- Inheritance
-
AbstractCursor<TResult>PaginatedCursor<T, TResult, BaseFindOptions<T, CollectionSortBuilder<T>>, CollectionFindCursor<T, TResult>>CollectionFindCursor<T, TResult>
- Implements
-
IEnumerable<TResult>IAsyncEnumerable<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
filterFilter<T>The filter to apply.
optionsBaseFindOptions<T, CollectionSortBuilder<T>>The find options to use.
Returns
- CollectionFindCursor<T, TResult>
A new cursor instance.