简体   繁体   English

如何根据Dynamo数据库表中的条件查询?

[英]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(String)是主排序键。

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". 我想在这种情况下在节点js函数中编写查询:“全选p_type =“ men”和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

Query work when you create GSI to p_type . Query GSI创建为p_typeQuery工作。

Another solution is 另一个解决方案是

You can use scan operator instead of query 您可以使用scan运算符代替query

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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