CosmosDB-正确的分区密钥 [英] CosmosDB - Correct Partition Key

查看:77
本文介绍了CosmosDB-正确的分区密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传到集合中的每个JSON文件都采用以下格式:

Every JSON file I upload to the collection is in the following format:

{
  "Blocks": [
    {
      "radarID": "51p01", ...
    },
    {
      "radarID": "51p02", ...
    }
  ]
}

我使用的分区键是'/Blocks/radarID',但是它不起作用.我猜想radarID不是Blocks的直接子代,而是在列表中.那么你知道我应该写什么作为分区键吗?

The partition key I use is '/Blocks/radarID', but it does not work. I guess radarID is not an immediate child of Blocks, it is in a list. So do you know what I should write as my partition key?

谢谢.

推荐答案

分区键对于每个文档必须为单个值,不能为子数组中的字段.分区键用于确定哪个数据库节点将承载您的文档,当然,如果您指定了多个值,则不可能.

Partition Key has to be a single value for each document, it can't be a field in sub-array. Partition Key is used to determine which database node will host your document, and it wouldn't be possible if you specified multiple values, of course.

如果单个文档包含来自多个实体的数据,并且您将分别查询这些实体,则可能有必要按每个实体拆分文档.如果所有这些雷达"都与某个更高级别的实体相关,请使用该实体ID作为分区键.

If your single document contains data from multiple entities, and you will query those entities separately, it might make sense to split your documents per entity. If all those "radars" are related to some higher level entity, use that entity ID as partition key.

最底线:分区键应由您的查询模式定义,以便针对单个分区执行最流行的查询.

Bottom line: partition key should be defined by your query patterns, so that the most popular queries are executed against a single partition.

这篇关于CosmosDB-正确的分区密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆