2017-05-06 9 views
0

C# 용 AWS SDK로 항목을 업데이트하려면 어떻게해야합니까?DynamoDB에서 목록의 항목을 업데이트하는 방법은 무엇입니까?

ItemName이 "eqq"일 때 "선택됨"값을 "TRUE"로 업데이트하려고합니다. DynamoDB의 테이블에

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); 

내 JSON 데이터는 아래의 구조 다음과 같습니다 :

나는 성공없이이 코드를 작성

{ 
    "Items": [ 
     { 
      "ImageSource": "checked.png", 
      "ItemName": "egg", 
      "Selected": true 
     }, 
     { 
      "ImageSource": "checked.png", 
      "ItemName": "Water", 
      "Selected": true 
     } 
    ], 
    "ListCategory": "Technology", 
    "ListCreator": "John", 
    "ListId": "e5a7ec9d-b00c-41f3-958a-84c8c183d702", 
    "ListName": "Test5", 
    "UpdateDateTıme": "2017-05-05T21:48:41.833Z" 
} 

답변

1

당신은 선험적으로 알 수 없습니다를 목록에있는 항목을 것입니다 ItemName의 달걀을 포함합니다. ItemName = egg를 가진 Items 목록의 0 번째 항목에서 항목을 읽은 다음 조건을 읽을 수 있습니다. 이 전략을 사용하면 항목을 먼저 읽어야하므로 알이 목록의 어떤 위치에 있는지 알 수 있습니다. 그렇지 않으면, 당신이 할 수 둥지지도의 항목 :

{ 
    "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" 
} 

다음과 같은 식을 사용

  1. UpdateExpression = ItemMap.egg.Selected = :bv
  2. ExpressionAttributeValues을 = {:bv: true}
  3. ConditionExpression = attribute_exists(ItemMap.egg) AND attribute_type(ItemMap.egg, M)
+0

고맙습니다. 훌륭한 아이디어입니다. :) 이것은 내가 찾고있는 것입니다. –