0

I am trying to upgrade my DocumentDB nuget package from 1.13 to 1.18

I am facing issue while upgrading my azure function which is having a DocumentClient binding.

In DocumentDB 1.13 the binding sections does not take :{Id} as an binding parameter and was creating the DocumentClient object perfectly . Whereas the DocumentDB 1.18 needs {Id} as an binding parameter [ Which i dont want , as I want to iterate through entire documents in the collection ]

my host.json binding before 1.18 was

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

my local.settings.json had only

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

and my azure 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);
    //}

}

}

Now when running the azure function with updated package of documentDB 1.18 it says to bind the {Id} which will give only the single document with the specified id . Whereas my requirment is same as the previous version of DocumentDB 1.13.

Please tell how can i get the entire documents binded with my DocumentClient with the new updated package.

Dinesh
  • 193
  • 2
  • 14

1 Answers1

0

According to your description, I checked this issue and reproduced this issue as follows:

enter image description here

Please tell how can i get the entire documents binded with my DocumentClient with the new updated package.

Based on your scenario, I would recommend you construct the DocumentClient by yourself instead of using the binding to DocumentClient for a workaround to achieve your purpose.

DocumentClient client = new DocumentClient(new Uri("https://<your-account-name>.documents.azure.com:443/"), "<your-account-key>");

And you could configure the serviceEndpoint and accountKey under your local.settings.json file just as the app setting AzureWebJobsStorage. Then you could use the following code for retrieving your setting value:

ConfigurationManager.AppSettings["your-appsetting-key"];

Moreover, here is a issue about constructing the DocumentClient from the connection string, you could refer to it.

UPDATE:

For 1.18, the following code could work as expected:

[FunctionName("Function1")]
public static void Run([TimerTrigger("*/10 * * * * *")]TimerInfo myTimer, [DocumentDB("brucedb01", "brucecoll01",ConnectionStringSetting = "AzureWebJobsDocumentDBConnectionString")] IEnumerable<dynamic> documents, TraceWriter log)
{
    foreach (JObject doc in documents)
    {
        //doc.SelectToken("_self").Value<string>();
        log.Info(doc.ToString());
    }
}

enter image description here

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
  • Hi Bruce , As the azure function allows us to bind the documentclient directly so would not like to create the documentclient object explicitly . In v. 1.13 of documentDB it works fine with the binding , but in 1.18 its failing as asking me to bind a single document with the id configured in the settings. My requirement is to bind the documentclient without Id. – Dinesh Oct 19 '17 at 14:45
  • I updated my answer for some research, you could refer to it. Moreover, I assumed that there be a bug, you could add your issue [here](https://github.com/Azure/azure-webjobs-sdk-extensions/issues). – Bruce Chen Oct 20 '17 at 09:48