如何在单表体系结构中使用扫描和查询-DynamoDB

我在我的项目中实现了一个表结构。我在使用DynamoDB扫描和查询方法时遇到了一些问题,因为在我的数据库中,我得到了有关不同模块的多个项目,例如:login,register..etc。因此,每个项目中的键都不相同。我只设置了用于识别yml中的Item的KeyType。我不知道如何在单表架构中使用扫描和查询方法。

如果我使用扫描方法,则会从数据库中获取整个项目。没有任何表达式或条件 ex:FilterExpression,KeyConditionExpression

my yaml file ex:
Resources:  
    TABLENAMEDynamoDBTable:
      Type: 'AWS::DynamoDB::Table'      
      Properties:
        AttributeDefinitions:
          -
            AttributeName: id
            AttributeType: S
        KeySchema:
          -
            AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: TABLENAME  

var params = {
    TableName: 'TABLENAME'   
};
dynamodb.scan(params,function(err,data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

输出:项目:[{......,...]

但是如果我使用表达式或条件,错误将通过。不仅扫描。在查询中也一样

var params = {
    TableName: 'TABLENAME',Limit: 10,FilterExpression:'#user =:val',ExpressionAttributeNames: {
        "#user": "status",},ExpressionAttributeValues: {
         ":val": 'active'
    }
};
dynamodb.scan(params,data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

我预期的输出

Item:[{status:'active',..},{status:'active',...]

但是我遇到了这个错误。

"message":"There were 7 validation
errors: InvalidParameterType: Expected params.ExpressionAttributeValues[':val'] to be a structure 
UnexpectedParameter: Unexpected key '0' found in params.ExpressionAttributeValues[':val']
UnexpectedParameter: Unexpected key '1' found in params.ExpressionAttributeValues[':val'] 
UnexpectedParameter: Unexpected key '2' found in params.ExpressionAttributeValues[':val'] 
UnexpectedParameter: Unexpected key '3' found in params.ExpressionAttributeValues[':val'] 
UnexpectedParameter: Unexpected key '4' found in params.ExpressionAttributeValues[':val'] 
UnexpectedParameter: Unexpected key '5' found in params.ExpressionAttributeValues[':val']... etc

因此任何人都可以解决此问题,并解释有关单表体系结构设计,扫描和查询以使用的信息。

ccdelan 回答:如何在单表体系结构中使用扫描和查询-DynamoDB

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167287.html

大家都在问