ReadFeeds vs Query vs Read in CosmosDB - azure-cosmosdb

I would like to verify if my understanding is correct about OperationType in Cosmos DB (Cassandra API), as I cannot find a good explanation in the documentation.
Basically I have run a few different cases on Cosmos DB, and I see that when I query data using partition key, then only ReadFeed is used. But when I am not using partition key, then OperationType "Query" is used. It means that apparently in the first case it doesn't use the query engine and goes directly to the storage and in the second case Query Engine is used. Does it sound right?

Read is when you Get a Document
The Get Document operation retrieves a document by its partition key and document key.
ReadFeed is when you List Documents
Performing a GET on the documents resource of a particular collection, i.e. the docs URI path, returns a list of documents under the collection. ReadFeed can be used to retrieve all documents, or just the incremental changes to documents within the collection.
Query is when you Query Documents (Search)
You can query arbitrary json documents in a collection by performing a post against the “colls” resource in Cosmos DB.
ReadFeed or change feed is an internal feature of Cosmos DB. Other DBs maintain a feed of changes as well. They may expose it and you can interact with it in the ways they make available. They will use the feed of changes internally for many things. Cosmos DB are probably able to satisfy your query when you filter by partition using the ReedFeed.

Related

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

Is it still a good idea to create comos db collection without partition key?

One colleague said that cosmos db will stop supporting collections without a partition key. But I can't find any information about this statement from Microsoft.
The application I'm working on has a collection of order records. A typical query returns 10s of thousands of these records. So if I use order id as partition key, it'll always run cross partition queries.... And the requirement is to get all records across all tenants, so partition by tenant id isn't an option, either.
I thought it'll be fine just create a collection without a partition key. I'll worry about archiving data later (probably with azure functions and change feed).
Is it a good idea to do so?
One colleague said that cosmos db will stop supporting collections
without a partition key. But I can't find any information about this
statement from Microsoft.
Based on the tips on the cosmos db portal,this message is confined to portal only so far.
You still could create non-partitioned collection by using sdk:
DocumentCollection collection = new DocumentCollection();
collection.set("id","jay");
ResourceResponse<DocumentCollection> createColl = client.createCollection("dbs/db",collection,null);
So,i think your service will not be affected by now. As for future trends, I suggest you pay more attention to Microsoft's official statement. If you have any special needs, you can submit feedback for help.

How to pass SP in Azure Search Data Source

I have 2 documents in a partition of document db. How can I combine these 2 documents and prepare one document which I can send as a Data Source for Azure Search Service.
I found a way by stored procedure we can combine 2 documents. Now I am facing a difficult scenario. Can we use a stored procedure in the query part of Azure search Data Source?
I am looking for a solution to read all the documents by partition
key.. is it possible by stored procedure.
Of course,it is possible to call the stored procedure by partition key. In fact, the partition key is necessary. You could refer to my previous case for more details:Azure Cosmos DB asking for partition key for store procedure.
Based on my researching, stored procedure can't be invoked in azure search data source.You could only configure sql database,cosmos db, blob storage ,table storage etc. So, I suggest you using Azure Function Http Trigger to call your stored procedure with sdk then save the combined document into new collection or save it as json file into blob storage corresponding to your Azure Search index.

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

Resources