简体   繁体   中英

How to query based on condition in dynamo db table?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM