question

ukaszOpasiak-3618 avatar image
2 Votes"
ukaszOpasiak-3618 asked VULE-0007 edited

Azure learning error: Can't bind CosmosDB to type 'System.String'

While doing the https://docs.microsoft.com/en-gb/learn/modules/chain-azure-functions-data-using-bindings/, "Exercise - Read data with input bindings", I'm getting error

> Can't bind CosmosDB to type 'System.String'. Possible causes: 1) Tried binding to 'Microsoft.Azure.Documents.Client.DocumentClient, Microsoft.Azure.DocumentDB.Core, Version=2.9.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' but user type assembly was 'System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.


Everything is set correctly, exactly the same as specified in the tutorial (I've done it x3 to be sure).


Seems like a bug to me.

azure-functionsazure-cosmos-db
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AngelEmanuelStevenRodriguezCastro-9036 avatar image
5 Votes"
AngelEmanuelStevenRodriguezCastro-9036 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLaude avatar image
0 Votes"
LeonLaude answered

Hi,

Q&A currently supports the products listed over here https://docs.microsoft.com/en-us/answers/products (more to be added later on).

You can reach the experts in the dedicated "Microsoft Learning - Microsoft Azure Training" forum over here:
https://trainingsupport.microsoft.com/en-us/tcml/forum/tcml_mat

(Please don't forget to accept helpful replies as answer)

Best regards,
Leon


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeinTon-7369 avatar image
2 Votes"
LeinTon-7369 answered UmasankarSivasubramanian-6553 commented

Looks like the CosmosDB input binding doesn't keep its configuration.

I had the same issue, edited the binding's config in function.json (removed the empty sqlquery and updated "id" to "Id".)
Then checked the CosmosDB input connection on the integration screen and found it empty.
After filling in the details again, the function started working.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please clear me on which key the "id" belongs to ?. its a value in partitionkey or actual value in key "id"?

1 Vote 1 ·
RyffJoao-9821 avatar image
5 Votes"
RyffJoao-9821 answered

Removes the "sqlQuery": "" from your function.json file

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

stefan-walter avatar image
3 Votes"
stefan-walter answered JeroenSanders-2004 commented

You have to remove manually the "sqlQuery": "" line from your binding in your file function.json. Afterward, your HTTP result code of 500 should change to 200.

Working Sample:

 {
       "name": "bookmark",
       "direction": "in",
       "type": "cosmosDB",
       "databaseName": "func-io-learn-db",
       "collectionName": "Bookmarks",
       "connectionStringSetting": "exercise-app-sw1980_DOCUMENTDB",
       "id": "id",
       "partitionKey": "id"
 }


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VULE-0007 avatar image
0 Votes"
VULE-0007 answered VULE-0007 edited

The value for id, partitionKey should be {id} to make it work
You should update the values in function.json like this:

  } 
        "name": "bookmark", 
        "direction": "in", 
        "type": "cosmosDB", 
        "databaseName": "func-io-learn-db", 
        "collectionName": "Bookmarks", 
        "connectionStringSetting": "exercise-app-sw1980_DOCUMENTDB", 
        "id": "{id}", 
        "partitionKey": "{id}" 
  } 




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.