Ann*_*Liu 1 amazon-web-services amazon-dynamodb
我有一张 dynamodb 表,一条记录如下:
{
"Items": [
{
"toObjectId": {
"S": "5678"
},
"keyValue": {
"S": "7890"
},
"aTypeId": {
"S": "test"
},
"aws:rep:deleting": {
"BOOL": false
},
"currentAt": {
"N": "1582476260000"
},
"keyTypeId": {
"S": "test2"
},
"aId": {
"S": "1234"
},
"aTypeId_keyTypeId_keyValue_currentAt": {
"S": "test_test2_7890_1582476260000"
},
"fromObjectId": {
"S": "12345"
},
}
],
"Count": 2562,
"ScannedCount": 2562,
"ConsumedCapacity": null
}
Run Code Online (Sandbox Code Playgroud)
如何使用 aws cli 编写一个 aws dynamodb 扫描/查询过滤器,以便在 aTypeId 为“test”时获取 aTypeId 和 aId?和
Primary partition key is aId (String)
Primary sort key is aTypeId_keyTypeId_keyValue_currentAt (String)
Run Code Online (Sandbox Code Playgroud)
我在下面尝试过,但没有幸运
aws dynamodb query \
--table-name test \
--key-condition-expression "aTypeId = :aTypeId" \
--expression-attribute-values '{
":aTypeId": { "S": "test" }
}'
Run Code Online (Sandbox Code Playgroud)
您的字段不在键或 GSI(全局二级索引)中,那么我认为您必须使用scan方法来获取对象aTypeId,
该查询将类似于:
aws dynamodb scan \
--table-name test \
--filter-expression "aTypeId = :typeValue" \
--projection-expression "aTypeId, aId" \
--expression-attribute-values '{":typeValue":{"S":"test"}}'
Run Code Online (Sandbox Code Playgroud)
如果您返回带有LastEvaluatedKey值的结果,这意味着您需要进行一个或多个查询才能获取所有数据:
aws dynamodb scan \
--table-name test \
--filter-expression "aTypeId = :typeValue" \
--projection-expression "aTypeId, aId" \
--starting-token VALUE_NEXT_TOKEN_OF_LAST_QUERY \
--expression-attribute-values '{":typeValue":{"S":"test"}}'
Run Code Online (Sandbox Code Playgroud)
但是,我建议使用哈希键创建 GSIaTypeId会更好。
| 归档时间: |
|
| 查看次数: |
12263 次 |
| 最近记录: |