Home > Blockchain >  Azure Functions error: The connection string for the monitored collection is in an invalid format
Azure Functions error: The connection string for the monitored collection is in an invalid format

Time:03-24

I created a Azure function that is triggered by Cosmos DB on local. And my function.json looks like below.

{
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "documents",
      "direction": "in",
      "leaseCollectionName": "leases",
      "connectionStringSetting": "DB_URI",
      "databaseName": "test",
      "collectionName": "messages",
      "createLeaseCollectionIfNotExists": true
    },
...

And I tried to run this function locally, then I got this error.

Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection Information for messages in database test with lease leases in database test : The connection string for the monitored collection is in an invalid format, please use AccountEndpoint=XXXXXX;AccountKey=XXXXXX;.

This error says I should use this format AccountEndpoint=XXXXXX;AccountKey=XXXXXX; as my connection string but my value looks like this currently.

local.settings.json

"DB_URI": "mongodb://...",

How and where can I get the valid value which I should put here? On Connection String page, I cannot find the value which uses the format above.

CodePudding user response:

The problem here is you are trying to connect to Mongo API account, I can see the url is starting with Mongo API,

From the docs,

Azure Cosmos DB bindings are only supported for use with the SQL API. For all other Azure Cosmos DB APIs, you should access the database from your function by using the static client for your API, including MongoDB API, Cassandra API, Gremlin API, and Table API.

  • Related