javascript - 使用nodejs在dynamodb中的列表中搜索

标签 javascript node.js amazon-web-services amazon-dynamodb hapi.js

我正在做一个项目,我们使用 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) {}

谁能帮我完成这个,谢谢

最佳答案

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

关于javascript - 使用nodejs在dynamodb中的列表中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46226774/

相关文章:

javascript - log4javascript - 日志消息中的行号

javascript - 在 Nodejs 中解析大型 JSON 文件

python-2.7 - 无法离线安装 s3cmd

amazon-web-services - 在 AWS 中如何使用 lambda 函数将文件从一个 s3 存储桶复制到另一个 s3 存储桶

amazon-web-services - aws beanstalk cloudformation 添加 CPUCreditBalance 警报

javascript - Vue.js:将函数绑定(bind)到模板

javascript - 如何使用参数转发注释高阶函数

node.js - MongoDb类型错误: Cannot read property 'insertMany' of undefined

javascript - 图像在 Canvas 中的位置不正确

node.js - 启动请求重复得太快且状态=203/EXEC