Amazon dynamodb 如何在DynamoDB中更新列表中的项目?
如何使用AWS SDK for C更新项目 假设当ItemName等于eqq时,我想将所选值更新为TRUE 我写了这段代码但没有成功:Amazon dynamodb 如何在DynamoDB中更新列表中的项目?,amazon-dynamodb,optimistic-locking,Amazon Dynamodb,Optimistic Locking,如何使用AWS SDK for C更新项目 假设当ItemName等于eqq时,我想将所选值更新为TRUE 我写了这段代码但没有成功: request = { ExpressionAttributeNames = new Dictionary<string, string>() { {"#I", "Items"}, {"#lN", item.ItemName} }, ExpressionAttributeValues =
request = {
ExpressionAttributeNames = new Dictionary<string, string>()
{
{"#I", "Items"},
{"#lN", item.ItemName}
},
ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
{
{ ":item", new AttributeValue
{ L = new List<AttributeValue> {
{ new AttributeValue
{ M = new Dictionary<string,AttributeValue> {
{ "ListName", new AttributeValue { S = "item.ItemName"} },
{ "Selected", new AttributeValue { BOOL = item.Selected} },
{ "ImageSource", new AttributeValue { S = item.ImageSource} }
}}
}
}}
}
},
UpdateExpression = "SET #I.#lN = :item"
// UpdateExpression = "SET #I = list_append(:item,#I )"
// UpdateExpression = "SET #I = :item"
};
var response = await client.UpdateItemAsync(request);
您无法预先知道列表中的哪个项将包含ItemName egg。您可以读取该项,然后对项列表中的第0项设置条件,该项的ItemName=egg。该策略要求您首先阅读项目,以便知道鸡蛋在列表中的位置。否则,您可以将项目嵌套在地图中:
{
"ItemMap": {
"egg":{
"ImageSource": "checked.png",
"Selected": true
},
"Water": {
"ImageSource": "checked.png",
"Selected": true
}
},
"ListCategory": "Technology",
"ListCreator": "John",
"ListId": "e5a7ec9d-b00c-41f3-958a-84c8c183d702",
"ListName": "Test5",
"UpdateDateTıme": "2017-05-05T21:48:41.833Z"
}
并使用以下表达式:
UpdateExpression=ItemMap.egg.Selected=:bv
ExpressionAttributeValues={:bv:true}
条件表达式=
属性_existsitemap.egg和属性_typeItemMap.egg,M
谢谢。这是个好主意:这就是我要找的。
{
"ItemMap": {
"egg":{
"ImageSource": "checked.png",
"Selected": true
},
"Water": {
"ImageSource": "checked.png",
"Selected": true
}
},
"ListCategory": "Technology",
"ListCreator": "John",
"ListId": "e5a7ec9d-b00c-41f3-958a-84c8c183d702",
"ListName": "Test5",
"UpdateDateTıme": "2017-05-05T21:48:41.833Z"
}