【发布时间】:2019-09-26 19:42:41
【问题描述】:
我有一个具有以下项目结构的 AWS DynamoDb 购物车表 -
{
"cart_id": "5e4d0f9f-f08c-45ae-986a-f1b5ac7b7c13",
"user_id": 1234,
"type": "OTHER",
"currency": "INR",
"created_date": 132432423,
"expiry": 132432425,
"total_amount": 90000,
"total_quantity": 2,
"items": [
{
"amount": 90000,
"category": "Laptops",
"name": "Apple MacBook Pro",
"quantity": 1
}
]
}
-
{
"cart_id": "12340f9f-f08c-45ae-986a-f1b5ac7b1234",
"user_id": 1234,
"type": "SPECIAL",
"currency": "INR",
"created_date": 132432423,
"expiry": 132432425,
"total_amount": 1000,
"total_quantity": 2,
"items": [
{
"amount": 1000,
"category": "Special",
"name": "Special Item",
"quantity": 1
}
]
}
该表将以 cart_id 作为主键,user_id 作为索引或 GSI,type 作为索引或 GSI。
我希望能够查询购物车表,
查找具有user_id = 1234 AND type != "SPECIAL" 的项目。
我不知道这是否意味着查询 -
--key-condition-expression "user_id = 1234 AND type != 'SPECIAL'"
我了解无法同时使用多个索引查询 AWS DynamoDb 表,
我遇到了以下问题,它有一个类似的用例,答案是建议创建一个复合键,
Querying with multiple local Secondary Index Dynamodb
是否意味着在表格中放入新项目时,
我将需要维护另一列,例如 user_id_type,
其值为1234SPECIAL 并为user_id_type 创建一个索引/ GSI?
示例项目结构 -
{
"cart_id": "5e4d0f9f-f08c-45ae-986a-f1b5ac7b7c13",
"user_id": 1234,
"type": "OTHER",
"user_id_type" : "1234OTHER",
"currency": "INR",
"created_date": 132432423,
"expiry": 132432425,
"total_amount": 90000,
"total_quantity": 2,
"items": [
{
"amount": 90000,
"category": "Laptops",
"name": "Apple MacBook Pro",
"quantity": 1
}
]
}
参考资料 -
1.Querying with multiple local Secondary Index Dynamodb
2.Is there a way to query multiple hash keys in DynamoDB?
【问题讨论】:
标签: amazon-web-services nosql amazon-dynamodb