我有一个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?