Join Chander Dhall for an in-depth discussion in this video Create database, part of Cosmos DB: Import, Manipulate, Index and Query.
- [Instructor] Here we are in the Azure portal and I'm going to search for Azure Cosmos DB which is by the way the new name for DocumentDB. And I'm going to pick Azure Cosmos DB. We could do both. We could also do database as a service for MongoDB, but for now we'll pick Azure Cosmos DB and hit Create. I'm going to use Cazton which is the name of my company CaztonDB and then pick the DocumentDB API and the subscription of your choice and have a resource group.
We're going to call that CaztonRG and since I'm in location West US, I'll go ahead and create it. It says CaztonRG is not available. So we can also try to give a different name, CaztonResource, and that seems to be available. I would check pin to dashboard and hit Create. All right, so deployment succeeded. As you can see, the resource group CaztonResource was created successfully.
You can see we have the URI and the primary key. So now let's go to Visual Studio and do some code. Now that we've created our Cosmos DB database, we're going to create a new project. You're free to pick any template of your choice, but in order to keep things simple, I'd like to use a console app. I'm going to call it Cazton which is the name of my company and hit OK. In order to get started, we need two things. One is the endpoint URL and the other one is simply the authorization key.
And we can get these values from the Azure portal. Click to copy and same for the key, we can just use the primary key for now. Next, we would need the DocumentDB client and we're going to get the nougat package.
Keep in mind that the name is still in transition. By the time you might watch this course, it might have changed to Cosmos DB. But as of now, if you search Cosmos DB, you will not find the package. And then create the DocumentClient. And since we don't have a reference, you should hit Control + Dot to resolve the reference and then call it client.
We would use the using statement just so we can predict the lifecycle of the DocumentClient. In this case, it will be the lifecycle of the using statement. And next thing would be the new URI, which in this case would be then .url and then the authorization key. Once we have that, we'll create our database and make sure we only create it if it doesn't exist and this is an async method. We'll pass in the name of the database. In this case, the id is Cazton.
Since it's an async method, I'll like to hit Wait to make sure that we create it and just hit Control + F5. Next, we can go to Document Explorer and then refresh and you can see that Cazton shows up so our database has been created.
- 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