查询非关键属性 [英] Query on non-key attribute

查看:46
本文介绍了查询非关键属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,dynamodb的 query 方法必须包括分区键作为过滤器的一部分。如果您不知道分区键怎么办?

It appears that dynamodb's query method must include the partition key as part of the filter. How can a query be performed if you do not know the partition key?

例如,您有一个用户表,其属性为 userid 设置为分区键。现在,我们要通过用户的电话号码查找他们。是否可以在没有分区键的情况下执行查询?使用 scan 方法可以实现此目标,但据我所知,这是以在应用过滤器之前从表中提取所有项目为代价的。

For example, you have a User table with the attribute userid set as the partition key. Now we want to look up a user by their phone number. Is it possible to perform the query without the partition key? Using the scan method, this goal can be achieved, but at the expense of pulling every item from the table before the filter is applied, as far as I know.

推荐答案

您需要设置全局二级索引(GSI),将您的 phoneNumber 列用作索引哈希键。

You'll need to set up a global secondary index (GSI), using your phoneNumber column as the index hash key.

您可以通过调用 UpdateTable

创建索引后,您就可以调用查询与您的 IndexName 一起,根据电话号码提取用户记录

Once you create the index, you'll be able to call Query with your IndexName, to pull user records based on the phone number.

这篇关于查询非关键属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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