azure - 邮递员:无法使用 Azure MongoDB API 创建文档
问题描述
使用Azure Cosmos DB: MongoDB API创建文档时,我面临以下因参数而异的问题。
创建 collectionUserProfile
时,我使用 Partition Key 创建了它username
。
Request1: - 没有分区键
标题:
x-ms-documentdb-is-upsert: true
身体:
{"username": "test"}
问题:
x-ms-partitionkey 标头中提供的分区键包含的组件少于集合中定义的组件。
Request2: - 使用分区键
标题:
x-ms-documentdb-is-upsert: true
x-ms-documentdb-partitionkey: ["username"]
身体:
{"username": "test"}
问题:
指定的输入之一无效
请求 3: - 在正文中指定了分区键和 id
标题:
x-ms-documentdb-is-upsert: true
x-ms-documentdb-partitionkey: ["username"]
身体:
{"id": "test", "username": "test"}
问题:
从文档中提取的 PartitionKey 与标题中指定的不匹配
任何状况之下,
我无法创建文档。创建指定分区的文档需要哪些参数?
解决方案
两点:
如果您使用的是 Mongo API,则不应使用 REST API。虽然技术上可行,但不支持同时使用两者。100% 不推荐。
分区键需要是分区键值,而不是路径本身,所以它将是“测试”,而不是“用户名”。它已经知道“用户名”是路径。
推荐阅读
- kubernetes - 在 hostPath 挂载的主机目录中看不到创建的文件
- typescript - esm.sh 和 jspm.org 在 deno 兼容性方面是否遵循相同的方法?
- amazon-web-services - 无法使用 awsvpc 网络类型与 ECS Fargate 上同一任务中的另一个容器通信
- python - python默认dict参数在函数调用中被缓存
- android - 如何在 Fragment 中设置 BottomNavigationView
- shell - 使用 AWK 递增数字
- ruby-on-rails - 不知道如何构建任务“路线”
- swift - 如何正确地从 CoreData 获取图像?
- python - 我如何从python中的模型中删除项目
- python - 远程连接不起作用。无法使用 python 套接字连接到服务器