Record1:
[{
"business_id": 2,
"user_id" = 5,
"forms": {
"f522": {
"id": "f522",
"is_deleted": 0,
"title": "Form 1"
},
"f8b6": {
"id": "f8b6",
"is_deleted": 0,
"title": "Form 2"
},
"fw56": {
"id": "fw56",
"is_deleted": 0,
"title": "Form 3"
}
}
}]
Record2:
[{
"business_id": 3,
"user_id" = 1,
"forms": {
"f788": {
"id": "f788",
"is_deleted": 0,
"title": "Form 11"
},
"f6yy": {
"id": "f6yy",
"is_deleted": 0,
"title": "Form 12"
},
"f00i": {
"id": "f00i",
"is_deleted": 0,
"title": "Form 13"
}
}
}]
Record3:
[{
"business_id": 4,
"user_id" = 3,
"forms": {
"f839": {
"id": "f839",
"is_deleted": 0,
"title": "Form 21"
},
"f1bc": {
"id": "f1bc",
"is_deleted": 0,
"title": "Form 22"
},
"f6ac": {
"id": "f6ac",
"is_deleted": 0,
"title": "Form 23"
}
}
}]
我有3条记录存储在dynamo-db表中。哈希键是business_id,范围键是user_id。 forms对象是具有子对象(id,is_deleted,title)的父对象。我不知道user_id值。但我只有business_id值" 2"(这是唯一的。不会在其他记录business_id中重复)。我想更新记录2 is_deleted值为1的id(值为f6yy)。如果可能,请建议查询。
答案 0 :(得分:0)
不,这是不可能的。
但作为替代路线,您可以通过替换新值来更新整个值。
答案 1 :(得分:0)
首先,用于dynamodb的AWS sdk需要更新操作的两个键值,因此两个键都是必需的,因为只能使用这两个键来识别条目。
其次:你提到了
(这是唯一的。不会在其他记录business_id中重复)
如果user_id和business_id的映射使得没有2个用户可以拥有相同的business_id,那么您可以只使用business_id作为主键而不使用user_id作为排序/范围键(因为它可以选择具有范围)键)。 user_id字段仍然存在,但它不再是范围键。
如果不是这种情况那么你可以做的是再次只使用一个键[上面提到的主键(business_id)]并将user_id与表单对象一起存储。我在这里假设表单对象与具有business_id的user_id相关。
新架构看起来像这样
{ "Record1": [
{
"business_id": 2,
"forms":
[
{
"user_id" : 5,
"f522": { "id": "f522", "is_deleted": 0, "title": "Form 1" },
"f8b6": { "id": "f8b6", "is_deleted": 0, "title": "Form 2" },
"fw56": { "id": "fw56", "is_deleted": 0, "title": "Form 3" }
}
]
}
]
}
更新操作现在变得非常重要,