簡體   English   中英

DynamoDB:不以

[英]DynamoDB: Does not begin with

我正在嘗試運行一個 DynamoDB 查詢,該查詢表示我想要不以特定值開頭的項目。 我似乎無法找到一種方法來做到這一點。

我嘗試了以下4種評估方式,但均無效。 每個都給我一個無效的操作員錯誤。

我嘗試過的KeyConditionExpression (s) 如下所示:

!begins_with(gameScoreId, :scoreScore) AND !begins_with(gameScoreId, :scoreLevel) AND userId = :userId

<>begins_with(gameScoreId, :scoreScore) AND <>begins_with(gameScoreId, :scoreLevel) AND userId = :userId

NOT begins_with(gameScoreId, :scoreScore) AND NOT begins_with(gameScoreId, :scoreLevel) AND userId = :userId

begins_with(gameScoreId, :scoreScore) = false AND begins_with(gameScoreId, :scoreLevel) = false AND userId = :userId

如果刪除 not 運算符,則會出現此錯誤:

KeyConditionExpressions 每個鍵只能包含一個條件

有沒有辦法在 dynamodb 中做到這一點?

看起來關鍵條件表達式不支持NOT begins_with(x) 這可能是因為結果集不連續(它是x x的項目聚合)。

一些可能的解決方案是:

  1. 使gameScoreId成為非關鍵屬性(或將其復制到新的非關鍵屬性),然后您可以查詢userId並過濾gameScoreId (您不能過濾關鍵屬性),或者
  2. 掃描表,在這種情況下,您可以應用要使用的過濾器表達式(顯然,對於非常大的表,您會遇到性能問題)
        .withFilterExpression("NOT begins_with(hashKey, :hKey)")
        .withExpressionAttributeValues(ImmutableMap.of(
                ":hKey", new AttributeValue().withS("somePrefix:")))

使用過濾器表達式時,這似乎對我有用。 我認為您的問題更多是在一個鍵上使用更多條件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM