Database Reference
In-Depth Information
Tip
The preceding update operation was performed on the table with
["Eng-
lish","German"]
as the content of the
Language
set.
The REST request body will update the item that has
BookTitle
as
SCJP
and
Author
as
Kathy
, thereby updating the
Language
set to hold English, German, and Latin. Now,
let's say that the same book has been published in another language (Greek). So, another
update request comes in from another client (who doesn't know that Latin is also there in
the
Language
set), as shown in the following code:
{
"TableName": "Tbl_Book",
"Key": {
"BookTitle": { "S": "SCJP" },
"Author": { "S": "Kathy" } },
"AttributeUpdates": {
"Language": {
"Value": { "SS": ["English","German","Greek"]},
"Action": "PUT" } },
"ReturnValues": "ALL_NEW"
}
Now, what happened? Even though the SCJP book written by Kathy is available in Latin,
it won't be available. So, what might have prevented this error is the use of the
Expec-
ted
field in the request. This is because, before adding a value to a
Language
set, the
user should have checked whether his/her update operation will affect or overwrite any
useful information that is already available in the set.
It is time to take a look at the code to avoid this issue. The code using the
Expected
field in the
UpdateItem
request body is as follows:
{
"TableName": "Tbl_Book",
"Key": {
"BookTitle": { "S": "SCJP" },
"Author": { "S": "Kathy" } },
"AttributeUpdates": {
"Language": {