要从表读取数据,请使用像 GetItem
、Query
或 Scan
这样的操作。默认情况下,Amazon DynamoDB 将返回所有项目属性。要仅获取部分而非全部属性,请使用投影表达式。
投影表达式 是用于标识您需要的属性的字符串。要检索单个属性,请指定其名称。对于多个属性,必须使用逗号分隔名称。
下面是投影表达式(基于指定项目属性中的 ProductCatalog
项目)的一些示例:
单个顶级属性。
Title
三个顶级属性。DynamoDB 检索整个 Color
集。
Title, Price, Color
四个顶级属性。DynamoDB 返回 RelatedItems
和 ProductReviews
的全部内容。
Title, Description, RelatedItems, ProductReviews
To read data from a table, you use operations such as GetItem
, Query
, or Scan
. Amazon DynamoDB returns all the item attributes by default. To get only some, rather than all of the attributes, use a projection expression.
A projection expression is a string that identifies the attributes that you want. To retrieve a single attribute, specify its name. For multiple attributes, the names must be comma-separated.
The following are some examples of projection expressions, based on the ProductCatalog
item from Specifying Item Attributes:
A single top-level attribute.
Title
Three top-level attributes. DynamoDB retrieves the entire Color
set.
Title, Price, Color
Four top-level attributes. DynamoDB returns the entire contents of RelatedItems
and ProductReviews
.
Title, Description, RelatedItems, ProductReviews
aws dynamodb get-item --table-name ProductCatalog --key file://key.json --projection-expression "Description, RelatedItems[0], ProductReviews.FiveStar"
要操作 Amazon DynamoDB 表中的数据,请使用 PutItem
、UpdateItem
和 DeleteItem
操作。(您还可使用 BatchWriteItem
在单个调用中执行多个 PutItem
或 DeleteItem
操作。)
对于这些数据处理操作,您可指定条件表达式 来确定应修改的项目。如果条件表达式的计算结果为 true,则操作成功;否则操作失败。
To manipulate data in an Amazon DynamoDB table, you use the PutItem
, UpdateItem
, and DeleteItem
operations. (You can also use BatchWriteItem
to perform multiple PutItem
or DeleteItem
operations in a single call.)
For these data manipulation operations, you can specify a condition expression to determine which items should be modified. If the condition expression evaluates to true, the operation succeeds; otherwise, the operation fails.
aws dynamodb update-item --table-name ProductCatalog --key ‘{"Id": {"N": "456"}}‘ --update-expression "SET Price = Price - :discount" --condition-expression "Price > :limit" --expression-attribute-values file://values.json
原文:https://www.cnblogs.com/cloudrivers/p/11628401.html