2017-05-06 5 views
0

C#のAWS SDKでアイテムを更新するにはどうすればよいですか?DynamoDBのリスト内のアイテムを更新するには?

ItemNameが "eqq"のとき、 "Selected"の値を "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

ありがとうございました。素晴らしいアイデアです:)これは私が探しているものです。 –

関連する問題