简体   繁体   English

从表中扫描多个电子邮件ID-DynamoDB

[英]Scan multiple email id from table - DynamoDB

I'm using @awspilot/dynamodb to fetch data from a customer table where customer_id is the primary key. 我正在使用@awspilot/dynamodb从其中customer_id是主键的客户表中获取数据。

I need to get customer id based on multiple customer_email . 我需要基于多个customer_email获取客户ID。

dynamodb
    .table('bc_customer')
    .select('customer_id')
    .having('email').eq('test@gmail.com')
    .scan(function( err, data ) {
        console.log(data);
  });

The above code allows me to pass single email id, is there any way to search on multiple email id? 上面的代码允许我传递单个电子邮件ID,是否可以搜索多个电子邮件ID?

DynamoDB supports query , which allows you to get data from one and only one partition (ie one partition key), or scan which returns every item in the table (ie a full table scan). DynamoDB支持query ,它允许您从一个分区和仅一个分区(即一个分区键)获取数据,或进行扫描以返回表中的每个项目(即全表扫描)。

If you know the partition keys to query, it will be faster to do multiple queries and combine your result set. 如果您知道要查询的分区键,则执行多个查询并合并结果集的速度会更快。 If you don't care about performance or you are happy with the speed (bear in mind a scan will scale poorly as your table grows) you can use a scan. 如果您不关心性能或对速度感到满意(请注意,随着表的增长,扫描的伸缩性会变差),则可以使用扫描。

Note that above you are actually doing a scan, and so you are not using your partition key as an index. 请注意,上面您实际上是在进行扫描,因此您没有将分区键用作索引。

A query would be like this: 查询将是这样的:

DynamoDB
    .table('bc_customer')
    .where('email').eq('test@gmail.com')
    .query(function(err, data ) {
        console.log(err,data)
    })

And a scan (I think - the awspilot documents are not too clear) should be something like: 扫描(我认为-awspilot文档不太清楚)应该是这样的:

DynamoDB
    .table('bc_customer')
    .having('email').eq('test@gmail.com')
    .having('someattribute').eq('something')
    .scan(function( err, data ) {
        console.log( err, data )
    })

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

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