Class CollectionFindCursor<T>
- Namespace
- DataStax.AstraDB.DataApi.Core.Enumeration
- Assembly
- DataStax.AstraDB.DataApi.dll
A cursor for finding and enumerating documents in a collection. This is a convenience class that uses the same type for both the document and result.
public class CollectionFindCursor<T> : CollectionFindCursor<T, T>, IDisposable, IEnumerable<T>, IEnumerable, IAsyncEnumerable<T> where T : class
Type Parameters
TThe type of the documents in the collection.
- Inheritance
-
CollectionFindCursor<T, T>CollectionFindCursor<T>
- Implements
-
IEnumerable<T>
- Inherited Members
Examples
// Basic usage with foreach
var cursor = collection.Find()
.Filter(Builders<MyDocument>.CollectionFilter.Eq(d => d.Status, "active"))
.Sort(Builders<MyDocument>.CollectionSort.Ascending(d => d.Name))
.Limit(10);
foreach (var doc in cursor)
{
Console.WriteLine(doc.Name);
}
// Async iteration
await foreach (var doc in cursor)
{
await ProcessDocumentAsync(doc);
}
Remarks
This cursor is returned by Find(CollectionFilter<T>, CollectionFindOptions<T>) and provides a fluent API for filtering, sorting, limiting, and projecting documents. It supports both synchronous and asynchronous iteration patterns.