我在我的DynamoDB表中有以下数据。
这是我的代码:
const userStatusParams = {
TableName: process.env.USERSTATUS_TABLE,
KeyConditionExpression: "loggedIn = :loggedIn",
ExpressionAttributeValues: {
":loggedIn": true
}
};
var usersResult;
try {
usersResult = await dynamoDbLib.call("query", userStatusParams);
console.log(usersResult);
}catch (e) {
console.log("Error occurred querying for users belong to group.");
console.log(e);
}
亚马逊返回了这个错误:
{ ValidationException: Query condition missed key schema element: userId
at Request.extractError ...
如何让它返回所有loggedIn == true的记录?
我的数据库目前是通过我的serverless.yml配置结构化的。
phoneNumberTable: #This table is used to track phone numbers used in the system.
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.phoneNumberTable}
AttributeDefinitions: #UserID in this case will be created once and constantly updated as it changes with status regarding the user.
- AttributeName: phoneNumber
AttributeType: S
KeySchema:
- AttributeName: phoneNumber
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}
WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}
我通过其他答案进行了一些研究,但无法解决我的情况。在其他答案中,他们使用了排序键,但我这里没有使用排序键。
我研究了一下其他回答,但无法解决我的问题。在其他回答中,他们使用了排序键,但我在这里没有使用排序键。
logged in = true
的字段,则必须使用filterExpression
进行scan
。 - Prakash Sharma