【问题标题】:search inside a list in dynamodb using nodejs使用 nodejs 在 dynamodb 的列表中搜索
【发布时间】:2017-09-15 03:43:03
【问题描述】:

我正在做一个项目,我们使用 Dynamodb 作为数据库,我有一个具有这种结构的文档:

{
   "shop_id": "hh-delightme",
   "shoppers": [
      {
        "email": "hatim.haffane@gmail.com",
        "name": "hatim haffane"
       },
       {
         "email": "xxx.zzz@gmail.com",
         "name": "bxdsf sdf sd f"
       }
     ]
  },{
   "shop_id": "it-delightme",
   "shoppers": [
       {
         "email": "hatim.haffane@gmail.com",
         "name": "hatim haffane"
        },
        {
         "email": "xxx.zzz@gmail.com",
         "name": "bxdsf sdf sd f"
        }
      ]
    }

我有两个索引 shop-id-index 和 email-index ,所以我想做的是让购物者在 shop_id “hh-delightme”中使用电子邮件“hatim.haffane@gmail.com”

我试过这段代码,但没有成功

var params = {
            TableName:"shopper",
            KeyConditionExpression:"shop_id = :shop_id AND email = :email",
            ExpressionAttributeValues: {
                ":shop_id":store,
                ":email":email
            }

        };

        docClient.query(params, function(err, data) {}

谁能帮我完成这个,谢谢

【问题讨论】:

    标签: javascript node.js amazon-web-services amazon-dynamodb hapijs


    【解决方案1】:

    我相信你不能同时查询两个索引。 您可以将查询更改为扫描 - 但这会更慢,因为它会为每个查询扫描整个表 - 或者您可以只查询一个索引。 我会查询您认为返回的结果数量最少的索引,可能是电子邮件,然后在您的 nodejs 代码中按 shop_id 过滤结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-09
      • 2021-11-17
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      相关资源
      最近更新 更多