所以我正在尝试使用以下代码在cosmos中创建一个新文档:
fun newDoc(key: String, data: Any, id: String){
policy.setConnectionMode(ConnectionMode.Direct);
val asyncClient = AsyncDocumentClient.Builder()
.withServiceEndpoint("https://ara-account-data.documents.azure.com:443/")
.withMasterKeyOrResourceToken(System.getenv("IOTDB") )
.withConnectionPolicy(policy)
.withConsistencyLevel(ConsistencyLevel.Eventual)
.build()
val doc =
Document(data, id, "user-$key")
val options = RequestOptions()
options.partitionKey = PartitionKey("user-$key")
val createDocumentObservable: Observable<ResourceResponse<com.microsoft.azure.cosmosdb.Document>> =
asyncClient.createDocument("dbs/Ara-android-database/colls/Ara-android-collection", doc, options, true)
createDocumentObservable
.single() // we know there will be one response
.subscribe(
{ documentResourceResponse: ResourceResponse<com.microsoft.azure.cosmosdb.Document> ->
println(
documentResourceResponse.requestCharge
)
},
{ error: Throwable ->
System.err.println("an error happened: " + error.message)
throw error
}
)
}
但我收到此错误
an error happened: ["PartitionKey extracted from document doesn't match the one specified in the header"],
RequestStartTime:“ 2020年2月20日01:40:14.716”,RequestEndTime:“ 2020年2月20日01:40:18.003”,持续时间:3287毫秒,尝试的区域数:1
任何帮助都会很棒:}