0

I have replaced secured data with placeholders

Error while running locally as well as after deploying -

Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.<Function-Name>'. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection Information for <Collection-Name> in database <Database-Name> with lease <Lease-Collection-Name> in database <Database-Name> : 
RequestUri: https://<Azure-Cosmos-DB-Account>.mongo.cosmos.azure.com/;
RequestMethod: GET;
Header: x-ms-version Length: 10;
Header: User-Agent Length: 48;
Header: x-ms-date Length: 29;
Header: Authorization Length: 82;
, Request URI: /, RequestStats: , SDK: Windows/10.0.18362 documentdb-netcore-sdk/2.10.1. Microsoft.Azure.DocumentDB.Core: 

local.settings.json file -

{
  "IsEncrypted": false,
  "Values": {
    "JAVA_OPTS": "-Djava.net.preferIPv4Stack=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005",
    "AzureWebJobsStorage": "<Required value>",
    "AzureWebJobsDashboard": "<Required value>",
    "AzureSignalRConnectionString": "<Endpoint connection string>",
    "AzureCosmosDBConnection": "AccountEndpoint=https://<Azure Cosmos Db Account>.mongo.cosmos.azure.com:443/;AccountKey=<Required key>",
    "FUNCTIONS_WORKER_RUNTIME": "java"
  },
  "Host": {
    "LocalHttpPort": 7071,
    "CORS": "http://localhost:8080,http://localhost:4200",
    "CORSCredentials": true
  }
}

Code -

@FunctionName("Notify-Update")
    public void notifyDBUpdate(
            @CosmosDBTrigger(name = "dataInput",
                    databaseName = "demo",
                    collectionName = "bagi",
                    leaseDatabaseName = "demo",
                    leaseCollectionName = "leasebagi",
                    createLeaseCollectionIfNotExists = true,
                    connectionStringSetting = "AzureCosmosDBConnection")
                    String document,
            @SignalROutput(name = "dataOutput", hubName = "chat", connectionStringSetting = "AzureSignalRConnectionString") OutputBinding<String> dataOutput,
            final ExecutionContext context) {

        context.getLogger().info("Java CosmosDB Notification trigger processed a request: " + document);

Collection and DB are already created but I haven't created lease collection.

I am working on realtime application using cosmos db, signalr and azure function but i am stuck with this error for quite some time now.

1 Answers1

0

You seem to be using a Mongo account (your endpoint is <Azure-Cosmos-DB-Account>.mongo.cosmos.azure.com).

As per the documentation:

Azure Cosmos DB bindings are only supported for use with the SQL API.

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
  • I understand that now, i missed reading the note on documentation page, thanks for your response, but can i use a static client for mongo connection in cosmos db trigger somehow ? if not i have no other option but to use a SQL DB, thanks – DEEP GAHLOT Apr 02 '20 at 06:20
  • You cannot use the Trigger with a Mongo account, the Trigger internally maintains clients that use the SQL API (that is why it is failing on your case), you cannot insert your own client in it to override it. In this case the only option is to use the SQL API if you want to use the Trigger in Azure Functions. – Matias Quaranta Apr 02 '20 at 16:23