如何在 DynamoDB 的主键上使用 begin_with 方法? [英] How can I Use begins_with method on primary key in DynamoDB?

查看:21
本文介绍了如何在 DynamoDB 的主键上使用 begin_with 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个属性 id(字符串,主键),值(字符串)的表.当我尝试遵循 KeyConditionExpression 时,它会抛出 Query key condition not supported.

I have Table with 2 attribute id(string,primary key), value(string). When I try follwoing KeyConditionExpression it throws Query key condition not supported.

KeyConditionExpression: "begins_with(ID, :tagIDValue)" 
                        or
KeyConditionExpression: "contains(ID, :tagIDValue)"

this 链接我知道我们只能使用 EQ主键上的操作.我怎样才能做到这一点

From this link I came to know we can use only EQ operations on main key. How can I achieve this

解决方法:=======================================================

我需要使用 begin_with 或 contains 来过滤所以我采用了以下方法.

I need to use begins_with or contains to filter So I went with following approach.

表属性:PK(partion_key, string), ID(sort key, string), value(string).

Table attributes: PK(partion_key, string), ID(sort key, string), value(string).

现在我的主键是基于 PK,ID 框架的

Now my primary key is framed based on PK,ID

PK 将具有所有行的恒定值.所以 KeyConditionExpression 会像.

PK will have constant value for all rows. so KeyConditionExpression will be like.

KeyConditionExpression: "PL = :pk  and begins_with(ID, :tagIDValue)"

注意:但仍然包含不能使用 KeyConditionExpression.我认为它已从 KeyConditionExpression 中删除

NOTE: But still contains not working with KeyConditionExpression. I think it was removed from KeyConditionExpression

推荐答案

begins_withcontains 在为primary指定一个EQ条件后,只能与范围键一起使用键.

You can use begins_with and contains only with a range key after specifying an EQ condition for the primary key.

要使用带有主键的 EQ,您可以这样做

To use EQ with the primary key you can do

KeyConditionExpression: "ID = :tagIDValue"

这篇关于如何在 DynamoDB 的主键上使用 begin_with 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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