2017-08-17 69 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

相关问题