How to change ConnectionMode in CosmosClient in Azure Functions?

384 Views Asked by At

I'm trying to change the ConnectionMode of my CosmosClient to Gateway. This is my Run() function:

        public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "policy")] HttpRequest req,
         [CosmosDB( databaseName:"AR", containerName: "Policy", Connection = "CosmosConnectionString")]CosmosClient cosmos, ILogger log)

And I'm wondering, how do I change the ConnectionMode to Gateway in that part of code? Obviously something like

[CosmosDB( databaseName:"AR", containerName: "Policy", Connection = "CosmosConnectionString")]CosmosClient cosmos = new CosmosClient{ConnectionMode.Gateway}

doesn't work.

Any ideas?

1

There are 1 best solutions below

0
Matias Quaranta On

It looks like from your code you are using the preview Webjob extension that uses the V3 SDK. The preview Webjob extension maintains the same behavior as the previous Webjob extension (3.X.X) and has Gateway as default mode. https://github.com/Azure/azure-webjobs-sdk-extensions/blob/dev/src/WebJobs.Extensions.CosmosDB/CosmosDBUtility.cs#L75