2

i am working on the sample example provided by microsoft in the link below https://anthonychu.ca/post/cosmosdb-real-time-azure-functions-signalr-service/ I have followed all the steps by i am getting the error below while running the code with azure function locally:

The listener for function 'Functions.OnDocumentsChanged' was unable to start. [2/18/2019 9:50:54 PM] The listener for function 'Functions.OnDocumentsChanged' was unable to start. Microsoft.Azure.Documents.ChangeFeedProcessor: The lease collection, if partitioned, must have partition key equal to id

enter image description here

SandeshR
  • 203
  • 2
  • 11

1 Answers1

2

The error message is quite clear, the Trigger uses a secondary (Leases) collection to store the state. On your Trigger definition you can specify, on the Configuration if you want to specify a particular Leases collection name / database name or leave the default ("leases"). The Trigger can also create the Leases collection for you if it does not exist through the CreateLeaseCollectionIfNotExists attribute.

In your case, you seem to already have the leases collection previously created.

The problem is that the leases collection, if it's partitioned, it needs to be by the /id that is what the error message is saying:

The lease collection, if partitioned, must have partition key equal to id

So to fix this scenario you can either:

  1. Delete your current leases collection and use CreateLeaseCollectionIfNotExists = true to let the Trigger create it for you.
  2. Manually create your leases collection and set /id as the Partition Key.
Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
  • Hi Matias Thanks for the response,i deleted the leases collection and added the line u mentioned,but now when i run the code is stuck at [2/20/2019 3:07:35 AM] Host lock lease acquired by instance ID '0000000000000000000000001E2F93C0'. – SandeshR Feb 20 '19 at 03:10
  • 1
    That means that the Function was initialized. Are you making changes in the Cosmos DB collection to trigger the Function? – Matias Quaranta Feb 20 '19 at 16:31