即使值匹配,文档和标头之间的 CosmosDB 分区键值不匹配也会出现错误
php小编西瓜在介绍CosmosDB时指出,即使值匹配,文档和标头之间的分区键值不匹配也会出现错误。CosmosDB是一种全球分布式数据库服务,它使用分区键将数据分布在不同的物理分区上。分区键是指在写入文档时指定的某个值,它决定了文档将被存储在哪个分区中。如果文档的分区键值与标头中指定的分区键值不匹配,将会导致错误的查询结果或者查询失败。因此,在使用CosmosDB时,我们需要确保文档的分区键值与标头中指定的分区键值保持一致,以避免出现错误。
问题内容
我正在使用 azure-sdk-for-go 包 azcosmos 在 cosmosdb 容器中创建项目。这是我当前收到的错误:
-------------------------------------------------------------------------------- response 400: 400 bad request error code: badrequest -------------------------------------------------------------------------------- { "code": "badrequest", "message": "message: {"errors":["partitionkey extracted from document doesn't match the one specified in the header. learn more: https:\/\/aka.ms\/cosmosdb\/sql\/errors\/wrong-pk-value"]}rnactivityid: 9ef3ec05-b381-48c8-bd4e-96a7cb764041, request uri: /apps/d27ef9bf-18ce-4431-b8de-709648aab568/services/2c472c3b-bd86-4593-8539-814c29caac51/partitions/31299a87-b895-4b13-91c0-788756ca5ff3/replicas/132790818155726834p/, requeststats: rnrequeststarttime: 2023-02-23t20:53:15.4424439z, requestendtime: 2023-02-23t20:53:15.4424439z, number of regions attempted:1rn{"systemhistory":[{"dateutc":"2023-02-23t20:52:06.4715437z","cpu":1.012,"memory":479419988.000,"threadinfo":{"isthreadstarving":"false","threadwaitintervalinms":0.0224,"availablethreads":32764,"minthreads":52,"maxthreads":32767},"numberofopentcpconnection":431},{"dateutc":"2023-02-23t20:52:16.4816322z","cpu":2.342,"memory":480026956.000,"threadinfo":{"isthreadstarving":"false","threadwaitintervalinms":0.0193,"availablethreads":32761,"minthreads":52,"maxthreads":32767},"numberofopentcpconnection":431},{"dateutc":"2023-02-23t20:52:26.4918299z","cpu":1.534,"memory":480000572.000,"threadinfo":{"isthreadstarving":"false","threadwaitintervalinms":0.0158,"availablethreads":32764,"minthreads":52,"maxthreads":32767},"numberofopentcpconnection":437},{"dateutc":"2023-02-23t20:52:36.5019603z","cpu":1.490,"memory":480000576.000,"threadinfo":{"isthreadstarving":"false","threadwaitintervalinms":0.0161,"availablethreads":32737,"minthreads":52,"maxthreads":32767},"numberofopentcpconnection":438},{"dateutc":"2023-02-23t20:52:46.5121122z","cpu":1.306,"memory":479989504.000,"threadinfo":{"isthreadstarving":"false","threadwaitintervalinms":0.0204,"availablethreads":32762,"minthreads":52,"maxthreads":32767},"numberofopentcpconnection":438},{"dateutc":"2023-02-23t20:53:06.5323276z","cpu":1.561,"memory":479914676.000,"threadinfo":{"isthreadstarving":"false","threadwaitintervalinms":0.0113,"availablethreads":32763,"minthreads":52,"maxthreads":32767},"numberofopentcpconnection":424}]}rnrequeststart: 2023-02-23t20:53:15.4424439z; responsetime: 2023-02-23t20:53:15.4424439z; storeresult: storephysicaladdress: rntbd://cdb-ms-prod-westus1-fd44.documents.azure.com:14323/apps/d27ef9bf-18ce-4431-b8de-709648aab568/services/2c472c3b-bd86-4593-8539-814c29caac51/partitions/31299a87-b895-4b13-91c0-788756ca5ff3/replicas/132790818155726834p/, lsn: 9427, globalcommittedlsn: 9427, partitionkeyrangeid: 0, isvalid: true, statuscode: 400, substatuscode: 1001, requestcharge: 1.24, itemlsn: -1, sessiontoken: -1#9427, usinglocallsn: false, transportexception: null, belatencyms: 1.004, activityid: 9ef3ec05-b381-48c8-bd4e-96a7cb764041, retryafterinms: , transportrequesttimeline: {"requesttimeline":[{"event": "created", "starttimeutc": "2023-02-23t20:53:15.4424439z", "durationinms": 0.0115},{"event": "channelacquisitionstarted", "starttimeutc": "2023-02-23t20:53:15.4424554z", "durationinms": 0.0114},{"event": "pipelined", "starttimeutc": "2023-02-23t20:53:15.4424668z", "durationinms": 0.1556},{"event": "transit time", "starttimeutc": "2023-02-23t20:53:15.4426224z", "durationinms": 1.8731},{"event": "received", "starttimeutc": "2023-02-23t20:53:15.4444955z", "durationinms": 0.1408},{"event": "completed", "starttimeutc": "2023-02-23t20:53:15.4446363z", "durationinms": 0}],"serviceendpointstats":{"inflightrequests":1,"openconnections":1},"connectionstats":{"waitforconnectioninit":"false","callspendingreceive":0,"lastsendattempt":"2023-02-23t20:35:31.6351618z","lastsend":"2023-02-23t20:35:31.6351618z","lastreceive":"2023-02-23t20:35:31.6351618z"},"requestsizeinbytes":551,"requestbodysizeinbytes":26,"responsemetadatasizeinbytes":186,"responsebodysizeinbytes":166};rn resourcetype: document, operationtype: creatern, sdk: microsoft.azure.documents.common/2.14.0" } --------------------------------------------------------------------------------登录后复制