c# - 删除具有唯一键的 cosmos 文档而不先获取对象
问题描述
我的对象看起来像这样:
{
"documentType":"doc",
"relatedKey": "Person1",
"Color": "blue",
"Street": "SomeStreet",
}
分区键设置为 /documentType
UniqueKey设置为 /documentType,/relatedKey
现在如何通过发送 Partition key 和UniqueKey来直接删除文档?通过使用 Cosmos API?
这是一些代码来显示我想要实现的目标:
[HttpDelete]
[Route("{documentType}/{relatedKey}")]
public async Task<ActionResult<string>> DeleteDocument(string documentType, string relatedKey)
{
Document doc = await documentClient.DeleteDocumentAsync(String.Format("/dbs/{0}/colls/{1}/docs/{2}/{3}", database, collection, documentType, relatedKey), new RequestOptions { PartitionKey = new Microsoft.Azure.Documents.PartitionKey(documentType) });
return Ok("ExtensionDocument deleted");
}
我的主要困难是删除具有多个唯一键的对象,而不仅仅是 PartitionKey
只有一个 PartitionKey 我知道如何删除一个文档。
解决方案
您不能以这种方式删除文档。您必须使用 doc id 和分区键。
删除文档在这里
推荐阅读
- django - 为什么我的日志文件没有输出我的调试消息?(姜戈)
- javascript - jQuery自动完成接受初始值
- r - 从另一个有条件的变量创建新变量(循环??)
- authorization - 在 istio 中处理用户授权
- javascript - Puppeteer 页面不会在 .click() 之后加载,直到到达块的末尾
- python - Python“switch-case”字典不执行函数?
- c++ - 将指针转换为多维数组
- go - Go:从 UUID 中删除连字符
- python - pip 错误没有名为 traceback 的模块:“找不到满足需求回溯的版本(来自版本:无)”
- reactjs - 我如何在 react-native 中计算超过 2 个变量