DocumentDB Connect Account - DocumentDB

How Account is connected in DocumentDB?

To start the program against DocumentDB then first step is to connect. connect your DocumentDB account to the two points as mentioned below:

  • Endpoint
  • Authorization Key


The Endpoint is a URL to your DocumentDB account and is constructed by combining your DocumentDB account name with Consider a dashboard as shown below.

end point

Click on the created DocumentDB account. The details will be displayed as shown below.

click created documentdb

By selecting the ‘Keys’ option the additional information will be displayed as shown in the below figure. The URL to your DocumentDB account is seen, which you can use as your endpoint.


Authorization Key

The Authorization key contains credentials and there will be two types of keys. That is the master key allows full access to all resources within the account where resource tokens permit restricted access to specific resources.

Master Keys

  • There's nothing you can't do with a master key. You can blow away your entire database if you want, using the master key.
  • You definitely don't want to be sharing the master key or distributing it to client environments. As an added security measure, it's a good idea to change it frequently.
  • There are actually two master keys for each database account, the primary and the secondary as highlighted in the above screenshot.

Resource Tokens

  • You can also use resource tokens instead of a master key.
  • Connections based on resource tokens can only access the resources specified by the tokens and no other resources.
  • Resource tokens are based on user permissions, so first you create one or more users, and these are defined at the database level.
  • You create one or more permissions for each user, based on the resources that you want to allow each user to access.
  • Each permission generates a resource token that allows either read-only or full access to a given resource and that can be any user resource within the database.

Consider the console application which is created in chapter 3.

Step 1 : In the Program.cs file add the following references.

Step 2 : Add Endpoint URL and Authorization key. But in this example primary key is used as Authorization key.

Note: Both Endpoint URL and authorization key should be different.

Step 3 : The new instance of the DocumentClient should be created in asynchronous task called CreateDocumentClient and instantiate new DocumentClient.

Step 4 : Now, From Main method Call your asynchronous task.
The complete Program.cs file so far is given below:

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

DocumentDB Topics