AWS Dynamodb:是否可以仅使用排序键进行查询 [英] AWS Dynamodb: Is it possible to make a query only using sort key

查看:434
本文介绍了AWS Dynamodb:是否可以仅使用排序键进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,dynamodb社区,

Hi dynamodb community,

有问题的表是MLA_USER_AUTH。如您所见,它具有分区键和排序键。我希望能够同时使用user_id和email查询数据库。

So the table in question is MLA_USER_AUTH. As you see it has as partition key and as sort key. I want to be able to query the database using both user_id and email.

有时我需要找到与电子邮件关联的用户,有时还要找到userid。电子邮件和用户ID属性对于每个访问者都是唯一的。

Sometimes I need to find the user associated with the email and sometimes the userid. Both email and userid attributes are unique for every visitor. is there any way it can be done?

这是我当前的查询。这显然行不通。由于抛出错误:ValidationException:查询条件缺少关键模式元素:UserID

This is my current query. This obviously doesnt work. As it throws the error: ValidationException: Query condition missed key schema element: UserID

var params = {
        TableName : 'MLA_USER_AUTH',
        KeyConditionExpression: "Email = :email",
        ExpressionAttributeValues:{
            ":email": { "S" : email } 
        }
    };
    dynamodb.query(params, function(err, data) { 

GSI是我唯一的

谢谢,
Ninjasoar

Thanks, Ninjasoar

推荐答案

就像Mark B所说的那样,您需要 query 的分区键-您不能单独使用排序键。

As Mark B said, you need partition-key to query- you can't do it using sort-key alone.

因此,唯一的出路是使用电子邮件作为分区键来创建GSI。

So, the only way out for you is to create a GSI with email as the partition-key.

这篇关于AWS Dynamodb:是否可以仅使用排序键进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆