如何在动态表中查询没有范围键的分区键?

时间:2020-05-14 11:23:50

标签: amazon-web-services amazon-dynamodb

我有一个dynamodb表,定义为:

const params = {
      TableName: tableName,
      KeySchema: [
        { AttributeName: 'id', KeyType: 'HASH' }, // Partition key
        { AttributeName: 'timestamp', KeyType: 'RANGE' },
      ],
      AttributeDefinitions: [
        { AttributeName: 'id', AttributeType: 'S' },
        { AttributeName: 'timestamp', AttributeType: 'N' },
      ],
      ProvisionedThroughput: {
        ReadCapacityUnits: 10,
        WriteCapacityUnits: 10,
      },
    };
    return await dynamodb.createTable(params).promise();

id是分区键,而timestamp是排序键。我使用以下查询:

    const id = 'xxxx';
    const params = {
      TableName: this.tableName,
      ExpressionAttributeValues: {
        ':id': { S: id },
      },
      KeyConditionExpression: 'id = :id',
      ProjectionExpression: 'timestamp'
    };
    return this.dynamodbClient
      .query(params)
```'

when I run above query I got an error `ValidationException: The number of conditions on the keys is invalid`. I don't want to include sort key in the query. How can I make the query without sort key?

0 个答案:

没有答案