Ich habe den Artikel bei erfolgreicher Ausführung des Put Items aktualisiert und das Ergebnis wie erwartet erhalten.
Hinweis: Tests mit DynamoDB lokal durchgeführt.
ALL_NEW - Gibt alle Attribute des Elements zurück, wie sie nach dem UpdateItem-Vorgang angezeigt werden.
Beispielcode: -
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));
}
});
}
});
Ausgang: -
Adding a new item...
Added item: {}
Then Updating the item...
UpdateItem succeeded: {"Attributes":{"Pos":{"a":"1","b":"2","key":"1"},"postId":
"16"}}
Wirklich ist dies eine Konsequenz Frage, damit ich glaube nicht, Sie erwarten, dass die gleichen Ergebnisse mit sehen ein tatsächlicher DDB-Cluster – NightWolf