本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
重要
This section refers to API version 2011-12-05,
which is deprecated and should not be used for new
applications.
如需目前低階 的文件API,請參閱 Amazon DynamoDB API參考。
描述
依主索引鍵,刪除資料表中的單一項目。您可以執行條件式刪除操作,在項目存在或者項目具有預期的屬性值時予以刪除。
注意
如果指定 DeleteItem
而沒有屬性或值,則會刪除項目的所有屬性。
在未指定條件的情況下,DeleteItem
一律為等冪操作,在同一個項目或屬性上多次執行不會導致錯誤回應。
條件式刪除僅能用於在符合特定條件時刪除項目和屬性。如果符合條件,DynamoDB 會執行刪除。反之則不會刪除項目。
您可以在每次操作對一個屬性執行預期的條件式檢查。
請求
語法
// This header is abbreviated. // For a sample of a complete header, see DynamoDB 低階 API. POST / HTTP/1.1 x-amz-target: DynamoDB_20111205.DeleteItem content-type: application/x-amz-json-1.0 {"TableName":"Table1", "Key": {"HashKeyElement":{"S":"AttributeValue1"},"RangeKeyElement":{"N":"AttributeValue2"}}, "Expected":{"AttributeName3":{"Value":{"S":"AttributeValue3"}}}, "ReturnValues":"ALL_OLD"} }
名稱 | 描述 | 必要 |
---|---|---|
TableName
|
包含要刪除項目的資料表名稱。 類型:字串 |
是 |
Key
|
定義項目的主索引鍵。如需主索引鍵的詳細資訊,請參閱 主索引鍵。 類型: |
是 |
Expected
|
指定條件式刪除的屬性。 類型:屬性名稱映射。 |
否 |
Expected:AttributeName
|
條件式放置的屬性的名稱。 類型:字串 |
否 |
Expected:AttributeName: ExpectedAttributeValue |
使用此參數來指定屬性名稱值組的值是否已經存在。 如果該項目不存在「顏色」屬性,則下列JSON表示法會刪除該項目:
下列JSON表示法會在刪除項目之前檢查名為 "Color" 的屬性是否具有 "Yellow" 的現有值:
根據預設,如果使用
注意如果指定 |
否 |
ReturnValues
|
如果要在刪除前取得屬性名稱值組,請使用此參數。可能的參數值為 類型:字串 |
否 |
回應
語法
HTTP/1.1 200 OK
x-amzn-RequestId: CSOC7TJPLR0OOKIRLGOHVAICUFVV4KQNSO5AEMVJF66Q9ASUAAJG
content-type: application/x-amz-json-1.0
content-length: 353
Date: Tue, 12 Jul 2011 21:31:03 GMT
{"Attributes":
{"AttributeName3":{"SS":["AttributeValue3","AttributeValue4","AttributeValue5"]},
"AttributeName2":{"S":"AttributeValue2"},
"AttributeName1":{"N":"AttributeValue1"}
},
"ConsumedCapacityUnits":1
}
名稱 | 描述 |
---|---|
Attributes
|
如果 類型:屬性名稱值組陣列。 |
ConsumedCapacityUnits |
操作所使用的寫入容量單位數目。此值顯示套用至佈建輸送量的數字。刪除不存在項目上的請求會使用 1 個寫入容量單位。如需詳細資訊,請參閱 DynamoDB 佈建容量模式。 類型:數字 |
特殊錯誤
錯誤 | 描述 |
---|---|
ConditionalCheckFailedException
|
條件式檢查失敗。找不到預期的屬性值。 |
範例
請求範例
// This header is abbreviated. // For a sample of a complete header, see DynamoDB 低階 API. POST / HTTP/1.1 x-amz-target: DynamoDB_20111205.DeleteItem content-type: application/x-amz-json-1.0 {"TableName":"comp-table", "Key": {"HashKeyElement":{"S":"Mingus"},"RangeKeyElement":{"N":"200"}}, "Expected": {"status":{"Value":{"S":"shopping"}}}, "ReturnValues":"ALL_OLD" }
回應範例
HTTP/1.1 200 OK
x-amzn-RequestId: U9809LI6BBFJA5N2R0TB0P017JVV4KQNSO5AEMVJF66Q9ASUAAJG
content-type: application/x-amz-json-1.0
content-length: 353
Date: Tue, 12 Jul 2011 22:31:23 GMT
{"Attributes":
{"friends":{"SS":["Dooley","Ben","Daisy"]},
"status":{"S":"shopping"},
"time":{"N":"200"},
"user":{"S":"Mingus"}
},
"ConsumedCapacityUnits":1
}