diff --git a/src/DataStax.AstraDB.DataApi/Collections/Collection.cs b/src/DataStax.AstraDB.DataApi/Collections/Collection.cs
index 64465929..3339d934 100644
--- a/src/DataStax.AstraDB.DataApi/Collections/Collection.cs
+++ b/src/DataStax.AstraDB.DataApi/Collections/Collection.cs
@@ -16,6 +16,7 @@
using DataStax.AstraDB.DataApi.Core;
using DataStax.AstraDB.DataApi.Core.Commands;
+using DataStax.AstraDB.DataApi.Core.Enumeration;
using DataStax.AstraDB.DataApi.Core.Query;
using DataStax.AstraDB.DataApi.Core.Results;
using DataStax.AstraDB.DataApi.SerDes;
@@ -63,7 +64,7 @@ internal Collection(string collectionName, Database database, CommandOptions com
///
/// The type of the documents in the collection.
/// The type of the id field for documents in the collection.
-public class Collection : IQueryRunner> where T : class
+public class Collection where T : class
{
private readonly string _collectionName;
private readonly Database _database;
@@ -308,7 +309,7 @@ public Task DropAsync()
///
public T FindOne()
{
- return FindOne(null, new DocumentFindOptions(), null);
+ return FindOne(null, new CollectionFindOneOptions(), null);
}
///
@@ -317,7 +318,7 @@ public T FindOne()
///
public T FindOne(CommandOptions commandOptions)
{
- return FindOne(null, new DocumentFindOptions(), commandOptions);
+ return FindOne(null, new CollectionFindOneOptions(), commandOptions);
}
///
@@ -326,23 +327,23 @@ public T FindOne(CommandOptions commandOptions)
///
public T FindOne(CollectionFilter filter)
{
- return FindOne(filter, new DocumentFindOptions(), null);
+ return FindOne(filter, new CollectionFindOneOptions(), null);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public T FindOne(DocumentFindOptions findOptions)
+ ///
+ public T FindOne(CollectionFindOneOptions findOptions)
{
return FindOne(null, findOptions, null);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public T FindOne(DocumentFindOptions findOptions, CommandOptions commandOptions)
+ ///
+ public T FindOne(CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOne(null, findOptions, commandOptions);
}
@@ -353,23 +354,23 @@ public T FindOne(DocumentFindOptions findOptions, CommandOptions commandOptio
///
public T FindOne(CollectionFilter filter, CommandOptions commandOptions)
{
- return FindOne(filter, new DocumentFindOptions(), commandOptions);
+ return FindOne(filter, new CollectionFindOneOptions(), commandOptions);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public T FindOne(CollectionFilter filter, DocumentFindOptions findOptions)
+ ///
+ public T FindOne(CollectionFilter filter, CollectionFindOneOptions findOptions)
{
return FindOne(filter, findOptions, null);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public T FindOne(CollectionFilter filter, DocumentFindOptions findOptions, CommandOptions commandOptions)
+ ///
+ public T FindOne(CollectionFilter filter, CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOneAsync(filter, findOptions, commandOptions, true).ResultSync();
}
@@ -380,7 +381,7 @@ public T FindOne(CollectionFilter filter, DocumentFindOptions findOptions,
///
public TResult FindOne()
{
- return FindOne(null, new DocumentFindOptions(), null);
+ return FindOne(null, new CollectionFindOneOptions(), null);
}
///
@@ -389,32 +390,32 @@ public TResult FindOne()
///
public TResult FindOne(CommandOptions commandOptions)
{
- return FindOne(null, new DocumentFindOptions(), commandOptions);
+ return FindOne(null, new CollectionFindOneOptions(), commandOptions);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
+ ///
public TResult FindOne(CollectionFilter filter)
{
- return FindOne(filter, new DocumentFindOptions(), null);
+ return FindOne(filter, new CollectionFindOneOptions(), null);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public TResult FindOne(DocumentFindOptions findOptions)
+ ///
+ public TResult FindOne(CollectionFindOneOptions findOptions)
{
return FindOne(null, findOptions, null);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public TResult FindOne(DocumentFindOptions findOptions, CommandOptions commandOptions)
+ ///
+ public TResult FindOne(CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOne(null, findOptions, commandOptions);
}
@@ -425,23 +426,23 @@ public TResult FindOne(DocumentFindOptions findOptions, CommandOptio
///
public TResult FindOne(CollectionFilter filter, CommandOptions commandOptions)
{
- return FindOne(filter, new DocumentFindOptions(), commandOptions);
+ return FindOne(filter, new CollectionFindOneOptions(), commandOptions);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public TResult FindOne(CollectionFilter filter, DocumentFindOptions findOptions)
+ ///
+ public TResult FindOne(CollectionFilter filter, CollectionFindOneOptions findOptions)
{
return FindOne(filter, findOptions, null);
}
///
- /// Synchronous version of
+ /// Synchronous version of
///
- ///
- public TResult FindOne(CollectionFilter filter, DocumentFindOptions findOptions, CommandOptions commandOptions)
+ ///
+ public TResult FindOne(CollectionFilter filter, CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOneAsync(filter, findOptions, commandOptions, true).ResultSync();
}
@@ -452,32 +453,32 @@ public TResult FindOne(CollectionFilter filter, DocumentFindOptions<
///
public Task FindOneAsync()
{
- return FindOneAsync(null, new DocumentFindOptions(), null);
+ return FindOneAsync(null, new CollectionFindOneOptions(), null);
}
///
///
public Task FindOneAsync(CommandOptions commandOptions)
{
- return FindOneAsync(null, new DocumentFindOptions(), commandOptions);
+ return FindOneAsync(null, new CollectionFindOneOptions(), commandOptions);
}
///
- /// Returns a single document from the collection based on the provided .
- /// This will return the first document found, most often used in conjunction with .
- /// See for more details on sorting, projecting and the other options for finding a document.
+ /// Returns a single document from the collection based on the provided .
+ /// This will return the first document found, most often used in conjunction with .
+ /// See for more details on sorting, projecting and the other options for finding a document.
///
///
///
- public Task FindOneAsync(DocumentFindOptions findOptions)
+ public Task FindOneAsync(CollectionFindOneOptions findOptions)
{
return FindOneAsync(null, findOptions, null);
}
- ///
+ ///
///
///
- public Task FindOneAsync(DocumentFindOptions findOptions, CommandOptions commandOptions)
+ public Task FindOneAsync(CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOneAsync(null, findOptions, commandOptions);
}
@@ -495,7 +496,7 @@ public Task FindOneAsync(DocumentFindOptions findOptions, CommandOptions c
///
public Task FindOneAsync(CollectionFilter filter)
{
- return FindOneAsync(filter, new DocumentFindOptions(), null);
+ return FindOneAsync(filter, new CollectionFindOneOptions(), null);
}
///
@@ -503,22 +504,22 @@ public Task FindOneAsync(CollectionFilter filter)
///
public Task FindOneAsync(CollectionFilter filter, CommandOptions commandOptions)
{
- return FindOneAsync(filter, new DocumentFindOptions(), commandOptions);
+ return FindOneAsync(filter, new CollectionFindOneOptions(), commandOptions);
}
///
///
///
- public Task FindOneAsync(CollectionFilter filter, DocumentFindOptions findOptions)
+ public Task FindOneAsync(CollectionFilter filter, CollectionFindOneOptions findOptions)
{
return FindOneAsync(filter, findOptions, null);
}
- ///
+ ///
///
///
///
- public Task FindOneAsync(CollectionFilter filter, DocumentFindOptions findOptions, CommandOptions commandOptions)
+ public Task FindOneAsync(CollectionFilter filter, CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOneAsync(filter, findOptions, commandOptions, false);
}
@@ -534,14 +535,14 @@ public Task FindOneAsync(CollectionFilter filter, DocumentFindOptions f
///
public Task FindOneAsync()
{
- return FindOneAsync(null, new DocumentFindOptions(), null);
+ return FindOneAsync(null, new CollectionFindOneOptions(), null);
}
///
///
public Task FindOneAsync(CommandOptions commandOptions)
{
- return FindOneAsync(null, new DocumentFindOptions(), commandOptions);
+ return FindOneAsync(null, new CollectionFindOneOptions(), commandOptions);
}
///
@@ -550,22 +551,22 @@ public Task FindOneAsync(CommandOptions commandOptions)
///
/// var exclusiveProjection = Builders<FullObject>.Projection
/// .Exclude("PropertyTwo");
- /// var findOptions = new FindOptions<FullObject>()
+ /// var findOptions = new CollectionFindOneOptions<FullObject>()
/// {
/// Projection = exclusiveProjection
/// };
/// var result = await collection.FindOneAsync<ObjectWithoutPropertyTwo>(findOptions);
///
///
- public Task FindOneAsync(DocumentFindOptions findOptions)
+ public Task FindOneAsync(CollectionFindOneOptions findOptions)
{
return FindOneAsync(null, findOptions, null);
}
- ///
+ ///
///
///
- public Task FindOneAsync(DocumentFindOptions findOptions, CommandOptions commandOptions)
+ public Task FindOneAsync(CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOneAsync(null, findOptions, commandOptions);
}
@@ -575,39 +576,30 @@ public Task FindOneAsync(DocumentFindOptions findOptions, C
///
public Task FindOneAsync(CollectionFilter filter, CommandOptions commandOptions)
{
- return FindOneAsync(filter, new DocumentFindOptions(), commandOptions);
+ return FindOneAsync(filter, new CollectionFindOneOptions(), commandOptions);
}
- ///
+ ///
///
///
- public Task FindOneAsync(CollectionFilter filter, DocumentFindOptions findOptions)
+ public Task FindOneAsync(CollectionFilter filter, CollectionFindOneOptions findOptions)
{
return FindOneAsync(filter, findOptions, null);
}
- ///
+ ///
///
///
///
- public Task FindOneAsync(CollectionFilter filter, DocumentFindOptions findOptions, CommandOptions commandOptions)
+ public Task FindOneAsync(CollectionFilter filter, CollectionFindOneOptions findOptions, CommandOptions commandOptions)
{
return FindOneAsync(filter, findOptions, commandOptions, false);
}
- private async Task FindOneAsync(CollectionFilter filter, DocumentFindOptions findOptions, CommandOptions commandOptions, bool runSynchronously)
+ private async Task FindOneAsync(CollectionFilter filter, CollectionFindOneOptions findOptions, CommandOptions commandOptions, bool runSynchronously)
{
- findOptions = findOptions != null ? findOptions.Clone() : new DocumentFindOptions();
- if (filter != null)
- {
- if (findOptions.Filter == null)
- {
- findOptions.Filter = filter;
- } else
- {
- throw new ArgumentException("Cannot pass a filter both within FindOptions and as stand-alone argument");
- }
- }
+ findOptions = findOptions != null ? findOptions.Clone() : new CollectionFindOneOptions();
+ findOptions = findOptions.WithFilterParam(filter);
var command = CreateCommand("findOne").WithPayload(findOptions).AddCommandOptions(commandOptions);
var response = await command.RunAsyncReturnDocumentData, TResult, FindStatusResult>(runSynchronously).ConfigureAwait(false);
return response.Data.Document;
@@ -616,18 +608,17 @@ private async Task FindOneAsync(CollectionFilter filter, Do
///
/// Find documents in the collection.
///
- /// The Find() methods return a object that can be used to further structure the query
+ /// The Find() methods return a object that can be used to further structure the query
/// by adding Sort, Projection, Skip, Limit, etc. to affect the final results.
///
- /// The object can be directly enumerated both synchronously and asynchronously.
- /// Secondly, the results can be paged through more manually by using the method.
+ /// The object can be directly enumerated both synchronously and asynchronously.
///
///
///
/// Synchronous Enumeration:
///
- /// var FindEnumerator = collection.Find();
- /// foreach (var document in FindEnumerator)
+ /// var cursor = collection.Find();
+ /// foreach (var document in cursor)
/// {
/// // Process document
/// }
@@ -649,7 +640,7 @@ private async Task FindOneAsync(CollectionFilter filter, Do
/// however BulkOperationCancellationToken settings are ignored due to the nature of Enumeration.
/// If you need to enforce a timeout for the entire operation, you can pass a to GetAsyncEnumerator.
///
- public FindEnumerator> Find()
+ public CollectionFindCursor Find()
{
return Find(null, null);
}
@@ -664,24 +655,25 @@ public FindEnumerator> Find()
/// var results = collection.Find(filter).Sort(sort);
///
///
- public FindEnumerator> Find(CollectionFilter filter)
+ public CollectionFindCursor Find(CollectionFilter filter)
{
return Find(filter, null);
}
///
- ///
- public FindEnumerator> Find(CommandOptions commandOptions)
+ ///
+ public CollectionFindCursor Find(CollectionFindManyOptions findOptions)
{
- return Find(null, commandOptions);
+ return Find(null, findOptions);
}
///
///
- ///
- public FindEnumerator> Find(CollectionFilter filter, CommandOptions commandOptions)
+ ///
+ public CollectionFindCursor Find(CollectionFilter filter, CollectionFindManyOptions findOptions)
{
- return Find(filter, commandOptions);
+ findOptions ??= new CollectionFindManyOptions();
+ return new(findOptions.WithFilterParam(filter), null, RunFindManyAsync);
}
///
@@ -689,7 +681,7 @@ public FindEnumerator> Find(CollectionFilter f
/// The Find alternatives that accept a TResult type parameter allow for deserializing the document as a different type
/// (most commonly used when using projection to return a subset of fields)
///
- public FindEnumerator> Find() where TResult : class
+ public CollectionFindCursor Find() where TResult : class
{
return Find(null, null);
}
@@ -699,39 +691,43 @@ public FindEnumerator> Find() wher
/// The Find alternatives that accept a TResult type parameter allow for deserializing the document as a different type
/// (most commonly used when using projection to return a subset of fields)
///
- public FindEnumerator> Find(CollectionFilter filter) where TResult : class
+ public CollectionFindCursor Find(CollectionFilter filter) where TResult : class
{
return Find(filter, null);
}
- ///
+ ///
///
/// The Find alternatives that accept a TResult type parameter allow for deserializing the document as a different type
/// (most commonly used when using projection to return a subset of fields)
///
- public FindEnumerator> Find(CommandOptions commandOptions) where TResult : class
+ public CollectionFindCursor Find(CollectionFindManyOptions findOptions) where TResult : class
{
- return Find(null, commandOptions);
+ return Find(null, findOptions);
}
///
///
- ///
- public FindEnumerator> Find(CollectionFilter filter, CommandOptions commandOptions) where TResult : class
+ ///
+ public CollectionFindCursor Find(CollectionFilter filter, CollectionFindManyOptions findOptions) where TResult : class
{
- var findOptions = new DocumentFindManyOptions()
- {
- Filter = filter
- };
- return new FindEnumerator>(this, findOptions, commandOptions);
+ findOptions ??= new CollectionFindManyOptions();
+ return new(findOptions.WithFilterParam(filter), null, RunFindManyAsync);
}
- internal async Task, FindStatusResult>> RunFindManyAsync(Filter filter, IFindManyOptions> findOptions, CommandOptions commandOptions, bool runSynchronously)
+ internal async Task> RunFindManyAsync(CollectionFindCursor cursor, string nextPageState, bool runSynchronously) where TResult : class
{
- findOptions.Filter = filter;
- var command = CreateCommand("find").WithPayload(findOptions).AddCommandOptions(commandOptions);
+ var options = cursor.FindOptions.Clone();
+ options.PageState = nextPageState;
+
+ var command = CreateCommand("find").WithPayload(options).AddCommandOptions(cursor.CommandOptions);
var response = await command.RunAsyncReturnDocumentData, TResult, FindStatusResult>(runSynchronously).ConfigureAwait(false);
- return response;
+
+ return new FindPage(
+ response.Data.NextPageState,
+ response.Data.Items,
+ response.Status?.SortVector
+ );
}
///
@@ -2119,9 +2115,4 @@ internal Command CreateCommand(string name)
var optionsTree = GetOptionsTree().ToArray();
return new Command(name, _database.Client, optionsTree, new DatabaseCommandUrlBuilder(_database, _collectionName));
}
-
- Task, FindStatusResult>> IQueryRunner>.RunFindManyAsync