I dont know why i cant use aggregation

Sakib Ali Choudhary 225 Reputation points
2024-03-03T18:32:04.65+00:00

Hi,

I was wondering why my queries are not working when i am using aggregation in cosmos.

from azure.cosmos import CosmosClient, PartitionKey

cosmos_url = 'https://xxx.documents.azure.com:443/'
cosmos_key = 'xxx=='
client = CosmosClient(cosmos_url, cosmos_key)

# Define your Cosmos database and container
database_name = 'xxxx'
container_name = 'xxxx'
database = client.get_database_client(database_name)
container = database.get_container_client(container_name)

cosmos_query = "SELECT count(c.x) AS x FROM c WHERE (c.x= 'x')"

query_result = list(container.query_items(
    query=cosmos_query,
    enable_cross_partition_query=True 
))
for item in query_result:
    print(item)

Its giving me error as below :-

azure.cosmos.exceptions.CosmosHttpResponseError: (BadRequest) {"code":"BadRequest","message":"Query contains the following features, which the calling client does not support:\nNone NonValueAggregate \r\nActivityId:xxx, Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0"} 

While i am running the same query at the portal i am getting a result.

User's image

I am using azure-cosmos 4.5.1

and python 3.9

Please help

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,745 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. VasimTamboli 5,110 Reputation points
    2024-03-03T18:56:25.5166667+00:00

    Hi Sakib,

    Is possible can you try upgrading Phython SDK library that supports the value? - https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/sdk-python - this helped most of the users as per my experience.

    you also try alternate solution.

    cosmos_query = "SELECT c FROM c WHERE c.x = 'x'"

    query_result = list(container.query_items(

    query=cosmos_query,
    
    enable_cross_partition_query=True
    

    ))

    count = len(query_result) # Count the number of returned documents

    print(f"Count: {count}")

    Note- enable_cross_partition_query=True is only needed if your query need to access data from multipel partitions.

    Please accept if this answer if helped, do let me know if you have additional question.

    1 person found this answer helpful.
    0 comments No comments

  2. Carlos Milanes 0 Reputation points
    2025-01-24T18:42:22.57+00:00

    Hi @VasimTamboli is there any other solution.

    Im facing the same problem, and the alternative could serve for a small amount of data, but it not effective for a big one..

    @Anonymous @Sakib Ali Choudhary did you find any other solution?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.