首页 > 解决方案 > GSI 中使用 FilterExpression 的 DynamoDB 查询

问题描述

我正在尝试使用过滤器表达式在 GSI 中执行查询,但 AWS 一直告诉我找不到表达式。查询如下:

var tableQuery = {
        TableName: "posts",
        KeyConditionExpression: "#wy = :wkYr",
        FilterExpression: "#ac = :isAct",
        IndexName: "weekYear-date-index",
        ScanIndexForward: false,
        Limit: 50,
        ExpressionAttributeNames: {
            "#wy": "weekYear",
            "#ac": "isActive"
        },
        ExpressionAttributeValues: {
            ":wkYr": cWeekYear,
            ":isAct": {BOOL: true}
        }
    };

并显示错误:

An expression attribute value used in expression is not defined; attribute value: :isAct

我一直在尝试不同的方法,但似乎没有任何效果,有什么想法吗?

当前查询的控制台日志:

 {
  "TableName": "posts",
  "KeyConditionExpression": "#wy = :wkYr",
  "FilterExpression": "#ac = :isAct",
  "IndexName": "weekYear-date-index",
  "ScanIndexForward": false,
  "Limit": 50,
  "ExpressionAttributeNames": {
    "#wy": "weekYear",
    "#ac": "isActive"
  },
  "ExpressionAttributeValues": {
    ":wkYr": 2040,
    ":isAct": {
      "BOOL": true
    }
  }
}

标签: node.jsamazon-web-servicesamazon-dynamodb

解决方案


这就是你应该传递你的价值的方式 ":isAct": true


推荐阅读