The reason is explained in the error you are seeing:
Function1: The listener for function 'Function1' was unable to start. Microsoft.Azure.WebJobs.Extensions.DocumentDB: Either the source collection 'database' (in database 'database') or the lease collection 'leases' (in database 'database') does not exist. Both collections must exist before the listener starts. To automatically create the lease collection, set 'CreateLeaseCollectionIfNotExists' to 'true'. Microsoft.Azure.Documents.Client: Message: {"Errors":["Resource Not Found"]}
Both collections need to exist, the collection called database
in your case and the leases collection called leases
. As the message says, you can use CreateLeaseCollectionIfNotExists
to automatically create the leases collection, but the source collection needs to exists.
If you want to understand the reason behind the need of the leases collection, you can read it here. In short, as the Function reads the Change Feed, it needs to checkpoint its progress in order to be resilient to any restart/stop in a separate collection. This collection can be in the same Account or you can customize its account and database.