azure-webjobs-sdk-extensions icon indicating copy to clipboard operation
azure-webjobs-sdk-extensions copied to clipboard

CosmosDb input binding does not handle the partition key

Open alrod opened this issue 7 years ago • 2 comments

https://stackoverflow.com/questions/48736164/how-to-pull-partition-key-from-httptrigger-route-with-documentdb

alrod avatar Feb 13 '18 20:02 alrod

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)

DavidJFowler avatar Mar 02 '21 11:03 DavidJFowler

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

igorbaimos avatar Mar 20 '21 23:03 igorbaimos