Silent failure of Azure Function CosmosDB input binding

Jonathan Griffiths 96 Reputation points
2021-04-27T06:48:00.717+00:00

I have been following the exercise at this URL ...
https://learn.microsoft.com/en-us/learn/modules/chain-azure-functions-data-using-bindings/5-read-data-with-input-bindings-portal-lab?pivots=javascript

... and everything is OK until I get to the "Try it out" section at the end, at which point the function always returns "No bookmarks found", irrespective of what value I supply for the id parameter.

The logs for the Azure Function App all show the function executing successfully. However, the activity log on the CosmosDB side shows no activity, as if the database had not even been contacted.

Just to be clear, the code of the function (in index.js) is copied directly from the exercise instructions, and the function.json is as follows, (where jgfunctioniotestse is the name of my CosmosDB account). Also, the CosmosDB contains the five items indicated in the exercise (in database "func-io-learn-db", container "Bookmarks".

{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "bookmark",
"direction": "in",
"type": "cosmosDB",
"databaseName": "func-io-learn-db",
"collectionName": "Bookmarks",
"connectionStringSetting": "jgfunctioniotestse_DOCUMENTDB",
"id": "id",
"partitionKey": "/id"
}
]
}

This absence of error messages is making it hard to troubleshoot; can you suggest anywhere else I could look?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
919 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
2,617 questions
{count} votes

Accepted answer
  1. Andrew McMahon 121 Reputation points
    2021-04-30T04:28:59.897+00:00

    @Jonathan Griffiths looks like theres a conflict in the docs, would only work for me by updating the doc ID and partition key to {id}.

    https://stackoverflow.com/a/67135095

    so values in function.json look like:

       {  
           ...  
           "id": "{id}",  
           "partitionKey": "{id}",  
           ...  
       }  
    

    Hopefully that helps, but clarification from @ChaitanyaNaykodi-MSFT on whether the docs are incorrect or the input panel is generating the wrong structure would be great!

    Cheers!


3 additional answers

Sort by: Most helpful
  1. Chinedu 16 Reputation points
    2021-06-17T20:31:52.28+00:00

    I encountered this same problem, and found the answer on this page. Thanks to the OP for posting, and thanks @Andrew McMahon for posting a quick solution!

    Now if only Microsoft Learning team would fix this certification training material...

    No comments

  2. Matthew Heaney 6 Reputation points
    2021-06-21T19:01:13.287+00:00

    Likewise thanks for the solution/workaround.

    This is very frustrating. The exercise literally says "Partition key = /id (slash id; NOT curly brackets or any combination of curly brackets and slashes)". Find myself none wiser moving forward

    No comments

  3. Don Dexter 1 Reputation point
    2021-10-27T19:59:20.02+00:00

    Holy hell, thank you!. Been struggling with this lesson for over a day - this was the last broken bit.

    No comments