Azure Function fails with error message collection doesn’t exist

Azure Function fails with error message “Either the source collection ‘collection-name’ (in database ‘database-name’) or the lease collection ‘collection2-name’ (in database ‘database2-name’) does not exist. Both collections must exist before the listener starts. To automatically create the lease collection, set ‘CreateLeaseCollectionIfNotExists’ to ‘true'”

This means that either one or both of the Azure Cosmos containers required for the trigger to work do not exist or are not reachable to the Azure Function. The error itself will tell you which Azure Cosmos database and container is the trigger looking for based on your configuration.

  1. Verify the ConnectionStringSetting attribute and that it references a setting that exists in your Azure Function App. The value on this attribute shouldn’t be the Connection String itself, but the name of the Configuration Setting.
  2. Verify that the databaseName and collectionName exist in your Azure Cosmos account. If you are using automatic value replacement (using %settingName% patterns), make sure the name of the setting exists in your Azure Function App.
  3. If you don’t specify a LeaseCollectionName/leaseCollectionName, the default is “leases”. Verify that such container exists. Optionally you can set the CreateLeaseCollectionIfNotExists attribute in your Trigger to true to automatically create it.
  4. Verify your Azure Cosmos account’s Firewall configuration to see to see that it’s not it’s not blocking the Azure Function.

Note: Make sure you create a collection called “leases” in your database or set the CreateLeaseCollectionIfNotExists =true

Sources:

https://docs.microsoft.com/en-us/azure/cosmos-db/troubleshoot-changefeed-functions

Last modified: August 5, 2021

Author

Comments

Write a Reply or Comment