azure-webjobs-sdk-extensions
azure-webjobs-sdk-extensions copied to clipboard
CosmosDb input binding does not handle the partition key
https://stackoverflow.com/questions/48736164/how-to-pull-partition-key-from-httptrigger-route-with-documentdb
Any progress on this item? I notice that PartitionKey is also ignored when specifiying a SqlQuery.
e.g.
[FunctionName("GetTaskAssignment")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "task-assignments/{id}")] HttpRequest req,
[CosmosDB("%DatabaseName%", Constants.TaskEventsCollection,
ConnectionStringSetting = "CosmosDBConnection",
PartitionKey = "{id}",
SqlQuery = "SELECT TOP 1 * FROM TaskEvents r WHERE r.IsCurrent")]
IEnumerable<TaskEvent> taskEvents,
ILogger log)
{ ... }
ignores the partition key value. I had to use SqlQuery = "SELECT TOP 1 * FROM TaskEvents r WHERE r.TaskId = {id} AND r.IsCurrent"
to make it work correctly. (partition key is \TaskId
)
I have managed to get use of the partition key only when the document id is also specified.
Id = "{id}",
PartitionKey = "{id}"
Inspired from : https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/azure-functions/functions-bindings-cosmosdb.md#queue-trigger-look-up-id-from-json-1