2017-08-17 70 views
0

在添加包含PutItem一個新的項目,然後用UpdateItem具有設置爲ALL_NEW是它預期的返回值將是強烈一致的返回值更新呢?DynamoDB PutItem隨後的updateItem一致性ReturnValues ALL_NEW

例如放置物品;

{key: 1a a: 1} 

然後更新該項目;

{key: 1, b: 2} 

我希望ReturnValues:ALL_NEW返回

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

但它會出現,這是不是這樣的?

回答

0

我更新了放置項目成功執行的項目並獲得了預期的結果。

注意:在DynamoDB local上執行的測試。

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

相關問題