CosmosClientBuilder Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
CosmosClientBuilder(String) |
Extracts the account endpoint and key from the connection string. |
CosmosClientBuilder(String, AzureKeyCredential) |
Initialize a new CosmosConfiguration class that holds all the properties the CosmosClient requires with the account endpoint URI string and AzureKeyCredential. AzureKeyCredential enables changing/updating master-key/ResourceToken while CosmosClient is still in use. |
CosmosClientBuilder(String, TokenCredential) |
Initializes a new CosmosClientBuilder with a TokenCredential instance. |
CosmosClientBuilder(String, String) |
Initialize a new CosmosConfiguration class that holds all the properties the CosmosClient requires. |
CosmosClientBuilder(String)
- Source:
- CosmosClientBuilder.cs
Extracts the account endpoint and key from the connection string.
public CosmosClientBuilder (string connectionString);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (connectionString As String)
Parameters
- connectionString
- String
The connection string must contain AccountEndpoint and AccountKey or ResourceToken.
Examples
"AccountEndpoint=https://mytestcosmosaccount.documents.azure.com:443/;AccountKey={SecretAccountKey};"
Remarks
Emulator: To ignore SSL Certificate please suffix connectionstring with "DisableServerCertificateValidation=True;". When CosmosClientOptions.HttpClientFactory is used, SSL certificate needs to be handled appropriately. NOTE: DO NOT use this flag in production (only for emulator)
Applies to
CosmosClientBuilder(String, AzureKeyCredential)
- Source:
- CosmosClientBuilder.cs
Initialize a new CosmosConfiguration class that holds all the properties the CosmosClient requires with the account endpoint URI string and AzureKeyCredential. AzureKeyCredential enables changing/updating master-key/ResourceToken while CosmosClient is still in use.
public CosmosClientBuilder (string accountEndpoint, Azure.AzureKeyCredential authKeyOrResourceTokenCredential);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string * Azure.AzureKeyCredential -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (accountEndpoint As String, authKeyOrResourceTokenCredential As AzureKeyCredential)
Parameters
- accountEndpoint
- String
The Uri to the Cosmos Account. Example: https://{Cosmos Account Name}.documents.azure.com:443/
- authKeyOrResourceTokenCredential
- AzureKeyCredential
AzureKeyCredential with master-key or resource token.
Examples
The example below creates a new CosmosClientBuilder
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceTokenCredential: new AzureKeyCredential("SuperSecretKey"));
CosmosClient client = cosmosClientBuilder.Build();
The example below creates a new CosmosClientBuilder with a ConsistencyLevel and a list of preferred locations.
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceTokenCredential: new AzureKeyCredential("SuperSecretKey"))
.WithConsistencyLevel(ConsistencyLevel.Strong)
.WithApplicationRegion("East US 2");
CosmosClient client = cosmosClientBuilder.Build();
Remarks
AzureKeyCredential enables changing/updating master-key/ResourceToken whle CosmosClient is still in use.
Applies to
CosmosClientBuilder(String, TokenCredential)
- Source:
- CosmosClientBuilder.cs
Initializes a new CosmosClientBuilder with a TokenCredential instance.
public CosmosClientBuilder (string accountEndpoint, Azure.Core.TokenCredential tokenCredential);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string * Azure.Core.TokenCredential -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (accountEndpoint As String, tokenCredential As TokenCredential)
Parameters
- accountEndpoint
- String
The Uri to the Cosmos Account. Example: https://{Cosmos Account Name}.documents.azure.com:443/
- tokenCredential
- TokenCredential
An instance of TokenCredential
Examples
The example below creates a new CosmosClientBuilder using a TokenCredential.
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
tokenCredential: new DefaultAzureCredential());
CosmosClient client = cosmosClientBuilder.Build();
Applies to
CosmosClientBuilder(String, String)
- Source:
- CosmosClientBuilder.cs
Initialize a new CosmosConfiguration class that holds all the properties the CosmosClient requires.
public CosmosClientBuilder (string accountEndpoint, string authKeyOrResourceToken);
new Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder : string * string -> Microsoft.Azure.Cosmos.Fluent.CosmosClientBuilder
Public Sub New (accountEndpoint As String, authKeyOrResourceToken As String)
Parameters
- accountEndpoint
- String
The Uri to the Cosmos Account. Example: https://{Cosmos Account Name}.documents.azure.com:443/
- authKeyOrResourceToken
- String
The key to the account or resource token.
Examples
The example below creates a new CosmosClientBuilder
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceToken: "SuperSecretKey");
CosmosClient client = cosmosClientBuilder.Build();
The example below creates a new CosmosClientBuilder with a ConsistencyLevel and a list of preferred locations.
CosmosClientBuilder cosmosClientBuilder = new CosmosClientBuilder(
accountEndpoint: "https://testcosmos.documents.azure.com:443/",
authKeyOrResourceToken: "SuperSecretKey")
.WithConsistencyLevel(ConsistencyLevel.Strong)
.WithApplicationRegion("East US 2");
CosmosClient client = cosmosClientBuilder.Build();