CosmosDB icon indicating copy to clipboard operation
CosmosDB copied to clipboard

Get-CosmosDbDocument not able to query certain items from a container

Open Sachin27j opened this issue 2 years ago • 3 comments

Version - PowerShell 5.1 Host - ISE, Also tested on Azure Automation Account OS - Windows 10 CosmosDb Powershell version - 4.6.0

The following is returning me 0 items even though data is there in cosmosdb. Upon changing the value in the filter for c.dwnStrmAppName to something else, it does give me an output. Essentially, the cmd is working for some items with a certain partitionKey in cosmosdb but not working for others.

(Get-CosmosDbDocument -Context $newcosmosDbContext -CollectionId $cd_containerName -Query "SELECT c.createdOn FROM c WHERE c.env='preprod' and c.action='SPN Creation' and c.status='Success' and lower(c.dwnStrmAppName)=lower('XYZ')" -QueryEnableCrossPartition 1).createdOn |Select-Object -Last 1

Sachin27j avatar Jan 13 '23 08:01 Sachin27j

Did some more digging, apparently the query is only running for one physical partition, while there exists 2 partitions for the collection I am running it for. Anyone with any information related to this?

Sachin27j avatar Jan 13 '23 10:01 Sachin27j

Hi @Sachin27j - Because you're doing a cross partition query (using the -QueryEnableCrossPartition parameter), it should be executing the query on all physical partitions. So, I don't see why your query wouldn't return the results you expect.

Have you run the same query in the Azure Portal in the Cosmos DB explorer - and do you get the same output?

PlagueHO avatar Jan 21 '23 21:01 PlagueHO

Hi, I am also getting this issue (or similar). I have run the same query from the Azure portal as I have in my powershell instance. Powershell returns no record, Azure portal returns 1.

EDIT: To update further, I can get the record to return by specifying the document id and partition key, though this does defeat the point of my cross partition query...

IAmWhitBran avatar Jan 27 '23 17:01 IAmWhitBran