How to query based on condition in dynamo db table?

坚强是说给别人听的谎言 提交于 2019-12-13 03:49:02

问题


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:


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



来源:https://stackoverflow.com/questions/53167165/how-to-query-based-on-condition-in-dynamo-db-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!