2017-08-17 4 views
0

PutItemで新しい項目を追加し、UpdateItemで更新する場合、戻り値はALL_NEWに設定されていますが、DynamoDB PutItemとReturnValueとの整合性が保証されています。ALL_NEW

たとえば、アイテムを置く。

{key: 1a a: 1} 

次にアイテムを更新します。

{key: 1, b: 2} 

私はReturnValuesを期待:ALL_NEWは

{key: 1, a: 1, b: 2} 

を返すために、しかし、これは当てはまらないと思われますか?

答えて

0

私はput itemの実行が成功したときにアイテムを更新し、期待どおりの結果を得ました。

注:ローカルのDynamoDBでテストが実行されました。

ALL_NEW - UpdateItem操作後に と表示されるので、項目のすべての属性を返します。

サンプルコード: -

var docClient = new AWS.DynamoDB.DocumentClient(); 

var table = "post"; 

var paramsPut = { 
    TableName: table, 
    Item: { 
     "postId": '16', 
     "Pos": { 
      "key": "1a", "a": "1" 
     } 
    } 
}; 

var paramsUpdate = { 
    TableName: "post", 
    Key: { 
     "postId": "16" 
    }, 
    UpdateExpression: "SET Pos.#key = :keyVal, Pos.b = :keyVal2", 
    ExpressionAttributeNames: { 
     "#key": "key" 
    }, 
    ExpressionAttributeValues: { 
     ":keyVal": "1", 
     ":keyVal2": "2" 
    }, 
    ReturnValues: "ALL_NEW" 
}; 

console.log("Adding a new item..."); 
docClient.put(paramsPut, function (err, data) { 
    if (err) { 
     console.error("Unable to add item. Error JSON:", JSON.stringify(err, 
      null, 2)); 
    } else { 
     console.log("Added item:", JSON.stringify(data, null, 2)); 

     console.log("Then Updating the item..."); 
     docClient.update(paramsUpdate, function (err, data) { 
      if (err) { 
       console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2)); 
      } else { 
       console.log("UpdateItem succeeded:", JSON.stringify(data)); 
      } 
     }); 
    } 
}); 

出力: -

Adding a new item... 
Added item: {} 
Then Updating the item... 
UpdateItem succeeded: {"Attributes":{"Pos":{"a":"1","b":"2","key":"1"},"postId": 
"16"}} 
+0

は本当にこれは私があなたと同じ結果を見ることを期待したいと思ういけないので、一貫性の問題です実際のDDBクラスタ – NightWolf

関連する問題