cosmos db support different schema in a collection? - azure-cosmosdb

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

Related

ReadFeeds vs Query vs Read in 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.

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.

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.

Should we call it DocumentDb or CosmosDB SQL Api

I'm little bit confused with the naming.
First of all, is there any difference between Document DB and Cosmos DB Sql Api, or it is just another name?
Second, in order to access Cosmos DB Sql Api I have to use DocumentDB nuget package. Will it be ever renamed or DocumentDB naming stays relevant.
Third, in my code, when naming my classes, should I use DocumentDB, or CosmodDbSqlApi? E.g. DocumentDbStore, or CosmodDbSqlApiStore, etc...
DocumentDB has been rebranded to Cosmos DB and everything new related to it will be named Cosmos DB.
Some SDKs kept the old name for backwards compatibility sake but it should not be referenced as DocumentDB but rather Cosmos DB. CosmosDbStore the most appropriate way to name your class (at least in my opinion).

is there any query profiler in cosmos db?

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.

Resources