It's been 8 months since my last blog post of that nature and I think it's time for a new one. It is also my second most popular post so if you like them, I'll write them.
Let's go straight to the point. Here are 15 more things you should know about Cosmos DB.
- Cosmos DB always returns paged results. You can continue reading the rest of the pages by providing the continuation token that you got from the previous request.
MaxItemCountFeedOption property that you can provide for any request that returns results in Cosmos DB does NOT represent the total amount of documents that you will get back. It represents the maximum amount of items that a single page of results will return. This means that if you have 1000 documents in a collection and you set the
MaxItemCountto 10, you won't get 10 documents back but 1000 documents in pages of 10.
- There is no performance difference between an index of type
Hashand an index of type
Range. The only difference is the index size.
- Selecting only the properties you need when you perform a query will reduce the response time and the cost of the request.
- The only thing currently that can run cross partition stored procedures is the Bulk Executor library. It achieves that by getting a map of all the partition key ranges and executing against each one of them.
- Cosmos DB supports two different pricing models. Reserved throughput at the database level and reserved throughput at the collection level. They both have a minimum of 400 RU/s each.
- The database level reserved throughput also allows you to specify dedicated provisioned throughput at the collection level. This throughput is not shared with the rest of the database and it has nothing to do with how many RU/s your database is provisioned on.
- Cosmos DB now supports Cross-Origin Resource Sharing (CORS).
- Azure Functions support a Cosmos DB trigger which is a wrapper around the Change Feed processor. It is the simplest and easiest way to listen for document changes and addition in a collection.
- You can only order by a single property at a time in Cosmos DB. Multiple property ordering is currently not supported but it's being worked on.
- Your partition key choice should be a property that you always have when you query your Cosmos DB collection.
- You should never have to do any cross partition queries as part of your application's normal workflow, so choose your partition key wisely.
- While using the Cosmos DB C# SDK, never synchronise your Cosmos DB retrieval calls. Things like
.AsEnumerable().ToList()will synchronise a bunch of background operations that the SDK is doing and it will block your application. Instead, create a
IDocumentQueryby calling the
AsDocumentQuery()method and call the
- The best way to manage Cosmos DB using PowerShell is to use the unofficial Cosmos DB PowerShell module from Daniel Scott-Raynsford
- There is a C# library called Cosmonaut which will make the usage of Cosmos DB in your C# application insanely straightforward. Give it a go.