reserved keyword in dynamodb - Swift 3

2019-08-14 14:08发布

Here is code:

queryExpression.keyConditionExpression = "#userId= :userId"
queryExpression.expressionAttributeNames = ["#userId":"userId", "#status":"status"]
queryExpression.expressionAttributeValues = [":userId":userID, ":status":"accept"]
queryExpression.projectionExpression = "status"

but I got the following error and I didnt know that status word is a reserved word in DynamoDB:

Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=0 "(null)" UserInfo={message=Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: status, __type=com.amazon.coral.validate#ValidationException}

I have looked at the below link but I do not understand it and I can't find a Swift example. How do I accomplish this? http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ExpressionAttributeNames.html#Expressions.ExpressionAttributeNames.ReservedWords

I am new to DynamoDB things.

Thanks!

1条回答
虎瘦雄心在
2楼-- · 2019-08-14 14:28

Here is a list of all the reserved words in DynamoDB: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html

so ExpressionAttributeNames and expressionAttributeValues are ways of aliasing to use #fooattribute and :foovalue even if foo were a reserved word within the above list.

So in your case, I believe your error is because the term status is reserved, you may try changing your last line to be :

queryExpression.projectionExpression = "#status"

That way you wouldn't be using the reserved word, it would read the alias instead. That alias would resolve to your actual attribute name which might as well be status.

查看更多
登录 后发表回答