我想从DynamoDB检索项目名称,这是我的表属性之一。
这是我当前的代码:
export async function main(event, context) {
const data = JSON.parse(event.body);
const params = {
TableName: "dev-table",
KeyConditionExpression: "userId = :userId" ,
ConditionExpression: "projectId = :projectId",
ExpressionAttributeValues: {
":userId": event.requestContext.identity.cognitoIdentityId,
":projectId": data.projectId
}
};
try{
const result = await dynamoDbLib.call("query", params);
return success(result.Items);
}catch(e){
return failure(e);
}
}
但是我收到一个错误:
ExpressionAttributeValue中提供的值未在表达式中使用:键:{:projectId}
此错误来自何处?
如何从表中检索单个属性值?
ConditionExpression是deleteItem,putItem,transactWriteItems和updateItem方法的有效参数。对于查询方法,请对非关键属性使用FilterExpression参数:
export async function main(event, context) {
const data = JSON.parse(event.body);
const params = {
TableName: "dev-table",
KeyConditionExpression: "userId = :userId",
FilterExpression: "projectId = :projectId",
ExpressionAttributeValues: {
":userId": event.requestContext.identity.cognitoIdentityId,
":projectId": data.projectId
}
};
try {
const result = await dynamoDbLib.call("query", params);
return success(result.Items);
} catch(e) {
return failure(e);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句