From the docs I understand that I can query a CosmosDB by specifying a query in the attribute like so:
public static class DocByIdFromRouteDataUsingSqlQuery
{
[FunctionName("DocByIdFromRouteDataUsingSqlQuery")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post",
Route = "todoitems2/{id}")]HttpRequest req,
[CosmosDB("ToDoItems", "Items",
ConnectionStringSetting = "CosmosDBConnection",
SqlQuery = "select * from ToDoItems r where r.id = {id}")]
IEnumerable<ToDoItem> toDoItems,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
foreach (ToDoItem toDoItem in toDoItems)
{
log.LogInformation(toDoItem.Description);
}
return new OkResult();
}
}
But I don't want to setup a query in my attribute. I want to do that in the method. I want to do some if/else checks before I do a query to my CosmosDB.
I can't find any examples where to use something like a CosmosDbClient. Does such a thing exist?
So basically my question is, how can I run a query from inside my method instead of inside the attribute?