.Net Cosmos SDK returns empty results on a query without partition specified. Works fine when partition key provided.
Did I miss something?
Code for iterating:
var iterator = this.cosmosLinqQuery.GetFeedIterator(queryable);
var results = new List<Entity>();
while (iterator.HasMoreResults)
{
var result = await iterator.ReadNextAsync();
results.AddRange(result.Resource);
}
return results;
Code for creating queryable:
var options = new QueryRequestOptions()
{
PartitionKey = PartitionKey.None,
MaxItemCount = null,
MaxConcurrency = -1,
MaxBufferedItemCount = -1,
EnableScanInQuery = true,
};
IQueryable<Entity> queryable = container.GetItemLinqQueryable<Entity>(
requestOptions: options,
continuationToken: continuationToken,
allowSynchronousQueryExecution: true);
I believe the issue is with setting the PartitionKey
value to PartitionKey.None
in your query options here:
var options = new QueryRequestOptions()
{
PartitionKey = PartitionKey.None,
MaxItemCount = null,
MaxConcurrency = -1,
MaxBufferedItemCount = -1,
EnableScanInQuery = true,
};
Based on my understanding, you use PartitionKey.None
to get the documents that are created with no partition key (it is entirely possible to create a document without partition key). From the documentation here
:
The returned object represents a partition key value that allows creating and accessing documents without a value for partition key
Can you try by removing PartitionKey = PartitionKey.None
from your query request options? Something like:
var options = new QueryRequestOptions()
{
MaxItemCount = null,
MaxConcurrency = -1,
MaxBufferedItemCount = -1,
EnableScanInQuery = true,
};
Then you should be able to fetch all documents in a container.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.