From the course: Microsoft Azure Cosmos DB Developer Specialty (DP-420) Cert Prep by Microsoft Press
Implement a point operation that creates, updates, and deletes documents
From the course: Microsoft Azure Cosmos DB Developer Specialty (DP-420) Cert Prep by Microsoft Press
Implement a point operation that creates, updates, and deletes documents
Now, in the previous lesson, we worked with the SQL language, and I mentioned we'd take a look at the code a bit more in the next lesson. So here we are looking in the .NET SDK Version 3 for Cosmos DB. As we can see section by section here, if you have a human readable id value, that's going to make your life easier as a developer. I've mentioned that in the past that if you don't specify an id for each of your JSON docs, you'll get a globally unique identifier, which then when you're doing point reads, it's going to be more inconvenient than if you've selected by doing an override, by using a developer selected value for the ids that perhaps makes more sense. So long story short, ultimately this sample, C# code is showing us how to create a point read in .NET, and what you need to know for the exam isn't exactly how this C# works, just understanding what's required in order to do a point read. And you know that by now. Now, as far as writing a document, here we have another example. Now, here I want to bring out the fact that Cosmos DB doesn't support the update operation. Instead, you have what's called an upsert operation. What's that mean? Well, that's where you're in effect updating an existing JSON document, but you're doing so by doing a replace. You're inserting a new document in the old ones place. And this is showing some code on how you can do that with C#. Again, notice that I'm intentionally not digging deeply into the C# because that's not what the exam is going after. The exam is going to test your understanding of the capabilities in Cosmos and when you might want to go one way or another. It's not a programming exam, despite the fact that it's called the Cosmos DB Developer Certification. That's an important point. Now, it is true that the first version of the exam did have a large amount of C# code, but Microsoft, I think, realized that the language isn't the point. It's under pun intended with point. It's understanding the hows and whys that you would do this stuff as a developer. Here's a delete operation where we're grabbing variables for the partition key and the string. And again, we're taking advantage of the await methods that give us asynchronous computing power and parallel work working with Cosmos DB. So working in the context of the container object, we can use the DeleteItemAsync method and notice that we're specifying our value, our data, as well as the id and the partition key. So the point here is, again, pun intended, is that we're being as focused as possible like a laser. This is how I imagine point reads and point writes or point upserts. You're focusing in like a laser directly on a specific document because you know exactly what its identity is by means of its partition key value, as well as its document id value.
Contents
- (Locked)Learning objectives1m
- (Locked)Choose when to use a point operation versus a query operation1m 41s
- Implement a point operation that creates, updates, and deletes documents3m 15s
- (Locked)Implement an update by using a operation2m 48s
- (Locked)Manage multi-document transactions using SDK transactional batch2m 1s
- (Locked)Perform a multi-document load using SDK bulk1m 33s
- (Locked)Implement optimistic concurrency control using ETags2m 25s
- (Locked)Implement session consistency by using session tokens1m 28s
- (Locked)Implement a query operation that includes pagination2m 3s
- (Locked)Implement a query operation by using a continuation token1m 21s
- (Locked)Handle transient errors and 429s2m 36s
- (Locked)Specify TTL for a document1m 18s
- (Locked)Retrieve and use query metrics8m 5s
- (Locked)