Questions tagged [azure-cosmosdb-sqlapi]
1222 questions
5
votes
1 answer
How to write Azure Cosmos COUNT DISTINCT query
Goal:
To return the count of distinct values of a particular document field within a partition of a Cosmos collection.
Steps:
If I run the following query on my Azure Cosmos database,
SELECT DISTINCT c.field
FROM c
WHERE c.field = 'abc' AND…

user1857450
- 551
- 8
- 20
5
votes
1 answer
Get to underlying SQL for Cosmos DB Query generated via LINQ
I am creating a query to cosmos using Linq
This is converted into SQL which is then run to do the search
var modelName = "Mondeo";
var baseQuery = client.CreateDocumentQuery(StaticSettings.ProjectionsCollectionUri,
new FeedOptions {…

Paul
- 2,773
- 7
- 41
- 96
5
votes
1 answer
Error: The order by query does not have a corresponding composite index that it can be served from
When executing the following query I receive an error
select * from c order by c.Agent.LastStateChangeUnixTime desc,c.Priority asc
The order by query does not have a corresponding composite index that it can be served from
I have added a composite…

rbohac
- 199
- 1
- 2
- 6
5
votes
3 answers
How can i use "Not in" with ARRAY_CONTAINS in Cosmos DB?
I am New to Cosmos DB. I am retrieving records using SQL API.now i want to add "Not In" in ARRAY_CONTAINS. I did lots of R&D for the same but not able to find out any solutions.

Mitul Suthar
- 53
- 1
- 3
5
votes
2 answers
How to query CosmosDB for nested object value
How can I retrieve objects which match order_id = 9234029m, given this document in CosmosDB:
{
"order": {
"order_id": "9234029m",
"order_name": "name",
}
}
I have tried to query in CosmosDB Data Explorer, but it's not…

knutole
- 1,709
- 2
- 22
- 41
5
votes
1 answer
Automatic indexing in Comos DB
I'm trying to define indexing on few properties in Comos but I'm a little bit confused about automatic indexing. As per the Cosmos DB documentation:
By default, Azure Cosmos DB automatically indexes every property for all items in your container…

Ankit Vijay
- 3,752
- 4
- 30
- 53
5
votes
1 answer
Read the number of records from a collection using cosmos client to a console app
I am using cosmos client and C# to delete items from a collection. In the process I would like to check the number of records that are in the collection, I have the data part of it and the query but I am stuck at what to use since I will be only be…

Jai
- 155
- 2
- 9
5
votes
1 answer
deleting document from cosmos db using C# and cosmos client
I am new to Cosmos DB and after reading through the microsoft docs am attempting to delete records from a cosmos db. I have tried to follow the example as closely as possible. The record is being found and read but I am running into a not found…

Jai
- 155
- 2
- 9
5
votes
1 answer
Singleton Azure Cosmos DB client
Use a singleton Azure Cosmos DB client for the lifetime of your
application
Each DocumentClient instance is thread-safe and performs efficient
connection management and address caching when operating in Direct
Mode. To allow efficient…

Pingpong
- 7,681
- 21
- 83
- 209
5
votes
0 answers
Cosmos DB - Request Time out / Service is currently unavailable Error
We using cosmos DB and evaluating how the system will perform under load. With load as low as 7-9K request we are randomly getting Service is currently unavailable & Request Time out Error.
Has anyone else faced this issue?
Below is the code
CREATE…

nirag tibdewal
- 81
- 1
- 5
5
votes
1 answer
What is the advised way to query documents from different partitions in CosmosDB?
When using Azure Cosmos DB and querying one partition, i just specify the partition key in the FeedOptions.
But when i have to query n partitions, i have (afaik) 2 options:
Run a separate Task for every partition and merge the result in my…

Markus S.
- 2,602
- 13
- 44
5
votes
2 answers
High request-charge for very simple query in Azure Cosmos DB (SQL API)
In Azure Cosmos DB (SQL API) the following query charges 9356.66 RU's:
SELECT * FROM Core c WHERE c.id = @id -- @id is a GUID
In contrast the following more complex query charges only 6.84 RU's:
SELECT TOP 10 * FROM Core c WHERE c.type =…

driAn
- 3,245
- 4
- 41
- 57
5
votes
1 answer
Azure COSMOS DB how to query for contains in an array
How do I make a query to get documents where something contains in the documents array "roles"? I want to get the below document where Trainer is a element in the array.
"enabled": true,
"profilePicture": null,
"roles": [
"Trainer",
"Client"
…

Loc Dai Le
- 1,661
- 4
- 35
- 70
4
votes
1 answer
What exactly is Azure Cosmos DB's _ts based on?
I'd like some clarity around the _ts field, and exactly when the value is determined, especially as it relates to committing a write.
From a practical perspective, my question boils down to this:
If I execute this SQL query against a CosmosDb…

Travis Troyer
- 730
- 6
- 9
4
votes
1 answer
Acceptable encoding for Cosmos DB IDs to replace illegal characters?
I'm trying to store data in Cosmos DB where the IDs use a slash (/). However slash is an illegal character in Cosmos IDs. I initially tried to resolve this by URL encoding slashes (%2F) as that's the form I'd generally receive them in through API…

Rob Mosher
- 509
- 3
- 13