Join Chander Dhall for an in-depth discussion in this video Change collection performance, part of Cosmos DB: Import, Manipulate, Index and Query.
- [Instructor] So we've seen two ways of creating a partition collection, one was with the default indexing and the second one was with custom indexing. So we'll come in this line of code and the next thing what I like to show is how to change a performance of an existing collection. Again we'll create a static async method and we're probably not going to return anything so we'll just have a task as the return type. And then pass the database ID and the collection ID.
That's all we need and we can also pass in the throughput value but for now we'll hard code it. So we have document collection, collection equals await client, since we already have the client here it should technically work because we're going to call the function right here on line number 21. And we have read document collection async. And the first thing it needs is the link to document collection.
So we use a URI factory dot create document collection URI and in this case we have the database ID and the collection ID. So once we have the collection, we need the offer, which we can grab from client dot create offer query, 'cause we're going to have to query cosmos DB for this, and we'll say where, and this is just a lambda expression where it says resource link should equal the self link, which we can find inside a collection.
And then we can use link to say as innumerable and then all we need is the first value, so this is single. And we can print this value on the console, and say current offer is and the collection name just in case we want to make sure what collection we have is offer and collection dot ID.
Now ID is what gives you the name that you added and then self link will actually give you the cosmos DB ID which is the internal ID. But this is a name that's easy to remember. Well the next thing what we want to do is replace this offer with something else. So we can say await client dot replace offer async and create a new offer and in this case we can say offer version two and pass in the offer we have and then change the value, for example, in this case we had the true put of 10,000, we're going to say 12,000 and we can also print this value, however, what's better is to get the offer back from the client and do the same query again.
This way we know that the value we're getting back is coming from document DB. So in this case we still have the resource link and then we're going to use the same collection, self link property and do the same exact thing we did earlier which is as innumerable and then single. And then whatever value we have, you're going to say offer version two, in this case, just call it offerv2, and type cast it to version two.
And then print the value on the console. So now we're going to call the function change collection performance, in this case we had caston as the database, we could do it for anything, we had company and we had test, let's do this for test. Once we have that, we're going to say await, because it was an async function, and do control+F5. As you can see, the current offer has 10,000 as the offer throughput and then we get the value back as 12,000.
If we go back to the portal and hit refresh, we can see the current offer is 10,000 and after refreshing it becomes 12,000. So it worked.
- Data import scenarios
- Creating a database
- Creating a partitioned collection
- Data manipulation
- Importing documents with a stored procedure
- User-defined functions
- Excluding indexing at a document level
- Range indexing on strings
- Querying with SQL parameters
- Range operations