1
votes

I am trying to use COSMOS DB with the Azure function

My function looks like

[FunctionName("DeleteAVFeedAuditData")]
    public static async Task Run([TimerTrigger("0 0/1 * * * *")]TimerInfo myTimer,  [DocumentDB]DocumentClient client,
        TraceWriter log)
    {

        var c = client;
        log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
        var value=ConfigurationManager.AppSettings["AVAuditFlushAfterDays"];

        var collectionUri = UriFactory.CreateDocumentCollectionUri("AVFeedAudit", "AuditRecords");
        //var documents = client.CreateDocumentQuery(collectionUri,"Select * from c where c.EndedAt");

        //foreach (Document d in documents)
        //{
        //    await client.DeleteDocumentAsync(d.SelfLink);
        //}
      
    }
}

and local.settings.json

{
   "IsEncrypted": false,
   "Values": {
     "AzureWebJobsStorage": " 
  DefaultEndpointsProtocol=xxxxx/xxxxx==;EndpointSuffix=core.windows.net",
  "AzureWebJobsDashboard": "",
  "AzureWebJobsDocumentDBConnectionString": 
  "AccountEndpoint=xxxxx/;AccountKey=xxxx==;",
  }
}

I had configured the connection

"AzureWebJobsDocumentDBConnectionString" with the cosmosdb connection string which contains the #"endpointurl+key"

When trying to run the application . its saying ID of the document is required, whereas on google it says it will create the document client object based on the connection string.

Please advise me what wrong i am doing in the binding. As my object is to create the document client through which i can query the document and delete the document.

1

1 Answers

4
votes

Got the answer.

  1. install-package microsoft.azure.documentdb -version 1.13 [ Note - not version 1.17]
  2. go to local.settings.json and add ""AzureWebJobsDocumentDBConnectionString":
  3. go to host.json and add the assembly reference

    { "frameworks": { "net46": { "dependencies": { "Dynamitey": "1.0.2", "Microsoft.Azure.DocumentDB": "1.13.0", "Microsoft.Azure.WebJobs.Extensions.DocumentDB": "1.0.0" } } }

and it will create the DocumentClient object by which you can perform any CRUD operation on it.

Thanks