我是Azure的新手,正在尝试使用其CosmosDB进行评论。在文档中,建议对注释系统建模,如下所示:
Post item:
{
"id": "1",
"name": "What's new in the coolest Cloud",
"summary": "A blog post by someone real famous",
"recentComments": [
{"id": 1, "author": "anon", "comment": "something useful, I'm sure"},
{"id": 2, "author": "bob", "comment": "wisdom from the interwebs"},
{"id": 3, "author": "jane", "comment": "....."}
]
}
Comment items:
{
"postId": "1"
"comments": [
{"id": 4, "author": "anon", "comment": "more goodness"},
{"id": 5, "author": "bob", "comment": "tails from the field"},
...
{"id": 99, "author": "angry", "comment": "blah angry blah angry"}
]
},
{
"postId": "1"
"comments": [
{"id": 100, "author": "anon", "comment": "yet more"},
...
{"id": 199, "author": "bored", "comment": "will this ever end?"}
]
}
对于Post集合,我知道“ id”是一个很好的分区键,并且我知道如何插入和查询该项目。
我迷失了如何在语法和逻辑上插入和查询注释。对于评论集合:
什么是分区键?
如果用户要发布新评论,我将如何(逻辑和语法) 知道要插入哪个项目以及如何知道数组 已满,如果必须限制100,则我必须创建一个新项目 到达了吗?
关于上一个问题,请问这两个问题如何解决? 用户同时添加评论(交易)?如果先 用户填写了100个限制的最后一个空格,注释如何 来自第二个用户的用户知道它需要插入新的 项目?
如果我需要删除数组中间的项目50,我将如何重新调整所有注释以适合适当的数组?
答案 0 :(得分:1)
我们绝对不建议以此方式对数据建模。
永远不要嵌入无界数组。请查看此How to model and partition data on Azure Cosmos DB using a real-world example
谢谢。