在 NodeJS 中,排序键以使用 AWS.DynamoDB.DocumentClient 的子字符串开头的 get() 条目的正确语法是什么?

What is the proper syntax to get() entries where the sort key begins with a substring using AWS.DynamoDB.DocumentClient in NodeJS?

查询排序键以特定字符串开头的数据库条目的正确语法是什么?

我相信这与

类似
const query_params = { 
 TableName: 'my_table',
   Key: {
      my_primary_key: 'a_primary_key_value',
   },
   FilterExpression: "my_sort_key begins_with :string",
   ExpressionAttributeValues: { 
     ":string": "starts_with_substring" 
   }
};

后面跟着一个dynamoDb.get(query_params, ...,但这不太对。我收到 ValidationException: The provided key element does not match the schema 错误。

根据 SDK query documentation,您的查询参数应如下所示

{
    TableName: "my-table",
    KeyConditionExpression: "#pk= :pk And begins_with(#sk, :sk)",
    ExpressionAttributeValues: {
      ":pk": "a_primary_key_value",
      ":sk": "starts_with_substring"
    },
    ExpressionAttributeNames: {
      "#pk": "my_primary_key",
      "#sk": "my_sort_key"
    }
}

您还需要将 dynamoDb.get() 更改为 dynamoDb.query()