KeyConditionExpression

KeyConditionExpression

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

问题描述

我有2个属性id(字符串,主键),value(字符串)的表。
当我尝试跟随KeyConditionExpression时,它抛出不支持查询键条件

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)"

从链接中得知我们只能在主键上使用EQ操作。我该如何实现

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

解决方案:=========================== ============================

我需要

表属性:PK(partion_key,字符串),ID(排序键,字符串),value(字符串) )。

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对所有对象都具有恒定值行。

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_with 包含仅带有范围键。

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的主键上使用begins_with方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 08:40