'Azure function - .net isolated process / Cosmosdb input

i'm looking for a cosmosdb input sample. The official microsoft docs show no example.

Has anyone accomplished this? I tried the following code sniped without success:

public static Hello Run([TimerTrigger("1/1 * * * *")] MyInfo myTimer,
 [CosmosDBInput(
    databaseName: "db",
    collectionName: "col",
    ConnectionStringSetting = "CosmosDBConnection",
    SqlQuery = "SELECT * FROM c")] IReadOnlyList<Item> input,
FunctionContext context)
{

Here is the error:

Executed 'Functions.ReadC' (Failed,] System.Private.CoreLib: Exception while executing function: Functions.ReadC. System.Private.CoreLib: Result: Failure
Exception: Microsoft.Azure.Functions.Worker.Diagnostics.Exceptions.FunctionInputConverterException: Error converting 1 input parameters for Function 'ReadC': Cannot convert input parameter 'input' to type 'System.Collections.Generic.IReadOnlyList`1[[isocos.Item, isocos, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' from type 'System.String'.
[2022-04-20T20:13:09.897Z]    at Microsoft.Azure.Functions.Worker.Context.Features.DefaultModelBindingFeature.BindFunctionInput(FunctionContext context) in D:\a\1\s\src\DotNetWorker.Core\Context\Features\DefaultModelBindingFeature.cs:line 70


Solution 1:[1]

Your code should pretty much work, this is my working sample:

[Function("History")]
    public IActionResult Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get",
            Route = "realtimemessaging/{myId}")]HttpRequestData req,
        [CosmosDBInput(
            ConfigConstants.CosmosDbNameSetting,
            ConfigConstants.CosmosContainerNameSetting,
            Connection = ConfigConstants.CosmosConnectionStringSetting, 
            SqlQuery = "SELECT * FROM c WHERE c.PartitionKey = {myId}")] IEnumerable<RealtimeMessage> messages,
        FunctionContext context)
    {
        return new OkObjectResult(messages);
    }

My gues is you need to replace IReadOnlyList for IEnumerable

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1