How to query based on condition in dynamo db table

2019-08-18 05:15发布

I have Table with following items where p_id is Primary partition key and p_type (String) is a Primary sort key.

p_id    p_type    address    name       phone
1221    Men      

I want to write query in node js function with this condition: "select all where p_type ="men" and address.area="abc".

my address item is a map and it looks like this:

"address": {
    "M": {
      "area": {
        "S": "abc"
      },
      "city": {
        "S": "Bengaluru"
      },
}

How to achieve this. do i have to create global secondary index?if yes how to create it.

1条回答
干净又极端
2楼-- · 2019-08-18 05:41

You cannot use Query based on the sort key.

Query work when you create GSI to p_type.

Another solution is

You can use scan operator instead of query

查看更多
登录 后发表回答