Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
341 stars 44 forks source link

Query for simple type, paginated #90

Closed Mortana89 closed 5 years ago

Mortana89 commented 5 years ago

I'm trying to do a select distinct c.fieldName, but I'd like to use pagination for this, to be on the safe side if this list gets big. However, QueryMultiple doesn't seem to support pagination.

Doing .Query("select ...").Select(x => x.FieldName) doesn't seem to work either.

What's the best approach to get a paginated list of strings from Cosmos?

Elfocrash commented 5 years ago

Cosmos DB doesn't support both Query and LINQ predicates in the same DocumentQuery so the line you pasted isn't supported.

I think QueryMultiple would work but why don't you just use Query with WithPagination?

Here is an example: https://github.com/Elfocrash/Cosmonaut/blob/develop/samples/Cosmonaut.Console/Program.cs#L125

Mortana89 commented 5 years ago

Cosmos DB doesn't support both Query and LINQ predicates in the same DocumentQuery so the line you pasted isn't supported.

I think QueryMultiple would work but why don't you just use Query with WithPagination?

Here is an example: https://github.com/Elfocrash/Cosmonaut/blob/develop/samples/Cosmonaut.Console/Program.cs#L125

I use Query with WithPagination for all our 'list' api's, but this one's a bit special, there's no POCO behind the resultset I want to fetch. All the other list api's have a poco object where the result is casted to, but here I just need a string...

Elfocrash commented 5 years ago

Why don't you used the CosmonautClient then? You can use the QueryDocumentsAsync<> method and set the generic T to be a string. Then just add WithPagination on your request.

Mortana89 commented 5 years ago

That works, but where do you get the continuation token in the response from? As I can't seem to find it in the cosmonaut client :/

var results = await mdStore.CosmonautClient.QueryDocumentsAsync<string>( mdStore.DatabaseName, mdStore.CollectionName, queryHelper.Query, queryParams, new Microsoft.Azure.Documents.Client.FeedOptions() { EnableCrossPartitionQuery = true, RequestContinuation = continuationToken } );

Elfocrash commented 5 years ago

Sorry I meant the Query<T> method.

mdStore.CosmonautClient.Query<string>(mdStore.DatabaseName, mdStore.CollectionName, queryHelper.Query, queryParams).WithPagination().ToPagedListAsync()
Elfocrash commented 5 years ago

Closing this due to inactivity. Feel free to re-open it if this isn't resolved.

Mortana89 commented 5 years ago

That worked, thanks!