【发布时间】:2018-05-14 03:59:12
【问题描述】:
我的 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 ...
如何让它返回所有已登录 == 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}}
我通过其他答案对此进行了一些研究,但无法弄清楚我的情况。在其他答案中,他们有排序键,但我在这里没有使用排序键。
【问题讨论】:
-
如果你正在做
query,那么你必须传递主键,在你的情况下是userId -
你的意思是电话号码?
-
无论如何我在查询时都没有可用的主键
-
如果你想要所有的
logged in = true字段,那么你必须使用scan和filterExpression -
我在这里创建了一个修改后的问题来进一步解决我的问题,stackoverflow.com/questions/47585581/…
标签: node.js amazon-web-services amazon-dynamodb serverless-framework