[英]AWS dynamodb ScanInput ExpressionAttributeValue not working as expected
我寫了一個掃描查詢來獲取像這樣的唯一啟用的數據
const FilterExpression = 'enabled = :enabled';
const ExpressionAttributeValues = { ':enabled': { 'BOOL': true } };
const scanParameters: ScanInput = {
TableName,
ExclusiveStartKey: cursor ?? undefined,
Limit: Number(filter.limit) ?? undefined,
FilterExpression,
ExpressionAttributeValues,
};
但它不會返回任何值。 當我將 ExpressionAttributeValue 更改為
const ExpressionAttributeValues = { ':enabled': true };
它返回值但不滿足 ScanInput 的類型。 拋出這樣的錯誤
“類型 '{ ':enabled': boolean; }' 不可分配給類型 'ExpressionAttributeValueMap'。屬性 '':enabled'' 與索引簽名不兼容。”我知道的一種解決方案是創建一個新類型並分配值根據但為什么在掃描數據時類型 ScanInput 格式數據不起作用?
您沒有提供足夠的代碼來完全理解您的問題。 我在這里的假設是您正在混淆客戶端,這意味着您正在使用 DynamoDB JSON { 'BOOL': true }
為低級客戶端定義參數,但實際上您使用的是使用本機 JSON 的文檔客戶端。
/*
Convert the key JavaScript object you are retrieving to the
required Amazon DynamoDB record. The format of values specifies
the datatype. The following list demonstrates different
datatype formatting requirements:
String: "String",
NumAttribute: 1,
BoolAttribute: true,
ListAttribute: [1, "two", false],
MapAttribute: { foo: "bar" },
NullAttribute: null
*/
請確保您對所使用的客戶端使用正確的語法。
嘗試:
const params = {
TableName: TableName,
ExpressionAttributeNames: { "#enablee": "enabled"},
FilterExpression: "#enabled = :enabled",
ExpressionAttributeValues: {
":enabled": true
},
};
const data = await ddbDocClient.send(new ScanCommand(params));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.