MicrosoftDocs / azure-docs

Open source documentation of Microsoft Azure
https://docs.microsoft.com/azure
Creative Commons Attribution 4.0 International
10.28k stars 21.47k forks source link

It's not clear what should be in the ConnectionStringSetting #93923

Open urza opened 2 years ago

urza commented 2 years ago

I am trying to create azure function triggered by http event that writes to cosmos db

I am using Visual Studio 2022 preview. With these packages image

Following the documentation and provided examples, my function looks like this:

 public static class Beep
    {
        [FunctionName("Beep")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
            [CosmosDB(
                databaseName: "func1db",
                collectionName: "func1col",
                ConnectionStringSetting = "CosmosDbConnectionString"
                )] out dynamic document,

            ILogger log)
        {
            log.LogInformation("function beep");
            string name = req.Query["name"];
            document = new { id = Guid.NewGuid(), name = name };
            var responseMessage = $"{name} beep at {DateTime.Now:G}";
            return new OkObjectResult(responseMessage);
        }
    }

There are two problems with it:

  1. I dont know what to put into CosmosDbConnectionString - if I try to put the actuall connection string here to this cosmos db obtained from azure portal it doesnt work. And If there should be just a name and the actual connection string should be in host.json then I dont know how that should look like (not int the example).
  2. The out dynamic document parameter wont compile because async funcion cant have out param

Please provide functioning complete example of Azure function started by http trigger that writes to existing Cosmos db.

Thank you.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

BryanTrach-MSFT commented 2 years ago

@urza Thanks for the feedback! I have assigned the issue to the content author to investigate further and update the document as appropriate.

potatoqualitee commented 1 year ago

i still have no idea what should be in this connectionstringsetting and will have to check github to find out. please document when possible.