Issue:
Unable to use dates as a partitionkey using cosmos db binding in Function App.
Error message
1 | 2021-02-25T10:06:43.246 [Error] Executed 'Functions.DateAsPartitionKey' (Failed, Id=4b6caaf1-70b3-43f6-ad3b-6135690aaff8, Duration=989ms)Message: {"Errors":["PartitionKey extracted from document doesn't match the one specified in the header"]}ActivityId: 93031b95-f2b7-4671-be9b-d2b15bdbe699, Request URI: /apps/4ade04dd-f1a9-46ca-8ce8-d1d500ff6422/services/14f4e25c-4cdb-4c48-9698-7c2bd157131c/partitions/89f15a69-3e0b-4eac-88ed-4ec954b9d385/replicas/132587031061806885p/, RequestStats:RequestStartTime: 2021-02-25T10:06:42.9959386Z, RequestEndTime: 2021-02-25T10:06:42.9959386Z, Number of regions attempted:1ResponseTime: 2021-02-25T10:06:42.9959386Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westeurope1-fd59.documents.azure.com:14396/apps/4ade04dd-f1a9-46ca-8ce8-d1d500ff6422/services/14f4e25c-4cdb-4c48-9698-7c2bd157131c/partitions/89f15a69-3e0b-4eac-88ed-4ec954b9d385/replicas/132587031061806885p/, LSN: 10, GlobalCommittedLsn: 10, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 400, SubStatusCode: 1001, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#10, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Upsert, SDK: Microsoft.Azure.Documents.Common/2.11.0, Windows/10.0.14393 documentdb-netcore-sdk/2.9.2 |
Sample Project:
index.js
1 | module.exports = async function (context, req) { |
function.json
1 | { |
Possible solution:
1 | const CosmosClient = require("@azure/cosmos").CosmosClient; |
HTH. 2021-3-4 By Jacky