is there any query profiler in cosmos db? - azure-cosmosdb

I'm a newbie at cosmos db. and i'll be glad if someone help me to find how to catch queries that are going on local emulator. the reason why i'm asking is that now query string is appended in a few steps via linq and i need to be sure that query builder returns correct query string.
thanks in advance!

By the sound of it you are using the C# SDK and LINQ to query your database.
Once your LINQ query is ready you should be doing queryable.AsDocumentQuery() to generate a DocumentQuery object and the use that to do while(documentQuery.HasMoreResults) documentQuery.ExecuteNextAsync<yourtype>().
If that's not the case then you are using the SDK in an non optimal way.
All you need to do to get the generated SQL query is to do a .ToString() on the documentQuery object and you gonna get the translated query back.

In order to see the interactions between your application and Cosmos DB database, you can use Cosmos DB Profiler tool. It shows queries that are sent to Cosmos DB and stacktrace of relevant code that generated them.
The profiler shows statistics for each operation like duration, response status code, query execution metrics etc and also the request units for each request to a database what allows to optimize query costs.
It also alerts users about common pitfalls when using Cosmos DB and recommends how to resolve them.
Available reports provided by the profiler allow to analyze Cosmos DB usage by an application.

Related

Azure Cosmos settings history

Is it possible to review the history of changes to the setting of an Azure Cosmos database. I believe I am colliding with another them who is using the same Cosmos database. I would like to review all the setting that have changed since the database was created. Is that possible?
You can audit control plane operations for any Cosmos DB resource once it has been created. However, the account must be configured such that all control plane operations are done against the Cosmos DB resource provider and not through one of the data plane SDKs. See the link for details on this.
However, ARM does not support providing information on when a resource was created. This is a limitation of ARM, not Cosmos DB.
If you just wanna watch who did operations on your cosmos database, I think 'Activity Log' tab could help you. It records some message like screenshot below.
But I found that I can't get the details of the operations such as changing RU. By the way, I didn't find any documents saying how to review operations in cosmosdb. Or maybe you can provide more details about what information you wanna get from cosmosdb?

Querying the Cosmos DB Change Feed using SQL queries

I need to access Cosmos DB data through a middleware API that gives access to SQL queries but not the change feed (i.e. DocumentClient.CreateDocumentQuery() but not DocumentClient.CreateDocumentChangeFeedQuery()). Is it possible to query the change feed using regular SQL queries?
I was thinking about filtering documents on recent _ts but I am not sure timestamps are guaranteed to be monotonically increasing across entire collections due to potential clock drift across the VMs Cosmos DB runs on.
You cannot query the Change Feed using a SQL query. The Change Feed contains documents that have been inserted / updated, and any filtering needs to be done client-side after receiving such changes.

cosmos db support different schema in a collection?

I am trying to write a record with a different schema to an existing collection with records . I don't get a exception, but i don't see the new record.
Do I need to use a different collection?
DocumentDBRepository<ScheduleViewModel>.CreateItemAsync(task).GetAwaiter();
Cosmos DB doesn't care about what you put into to it (as almost any other nosql db), so this is supported from the Cosmos DB perspective. from the code perspective, I suppose you need to create a connection that would support the model your are using and create a document

Getting the size of each partition in a CosmosDB collection

Is it possible to get the size of every partition in a Cosmos DB collection? I know the portal will show the top few partitions in a collection, in the Metrics blade, but I'm interesting in seeing the size of every partition.
I believe you should be able to get this data through the Cosmos DB REST API.
It doesn't seem to be exposed through the .NET SDK so you'd need to write some C# or PowerShell yourself to access the data however, it should be available.
Link is:
https://learn.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/collectionpartition/listusages

Is there a way to do 'query execution plan ' in Firebase database? Similar to the usage of explain() in MongoDB?

Is there a way to validate execution cost of a query in Firebase database? Similar to the usage of explain() in MongoDB?
There is no query execution explanation in Firebase Database. To be honest, the types of queries you can currently build on the database are limited. So such a tool would be fairly static.
If you're not getting the results you expect or the performance you expect, share the minimal code to reproduce the problem and we'll help from there.

Resources