Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何使用主索引和全局辅助索引查询dynamo db_Amazon Web Services_Amazon Dynamodb - Fatal编程技术网

Amazon web services 如何使用主索引和全局辅助索引查询dynamo db

Amazon web services 如何使用主索引和全局辅助索引查询dynamo db,amazon-web-services,amazon-dynamodb,Amazon Web Services,Amazon Dynamodb,我有一个dynamodb查询: var unitsData = await(docClient.query({ TableName:"test-units-" + config.stage, IndexName:"unitOwnerIndexDev", KeyConditionExpression : 'ownerName= :hkey', ExpressionAttr

我有一个dynamodb查询:

var unitsData = await(docClient.query({
                TableName:"test-units-" + config.stage,
                IndexName:"unitOwnerIndexDev",
                KeyConditionExpression : 'ownerName= :hkey',
                ExpressionAttributeValues : {
                    ':hkey': event.ownerName
                },
                Key:{"unitID": event.unitID
                }
            }).promise());
我希望它只返回一行唯一的unitID和它的所有者。但是返回的数据对于unitID来说不是唯一的。它确实会根据所有者过滤掉。unitID是主键(散列),所有者是全局二级索引

这是我的桌子:

aws dynamodb create-table --table-name test-units-dev --attribute-definitions AttributeName=unitID,AttributeType=S AttributeName=ownerName,AttributeType=S --key-schema AttributeName=unitID,KeyType=HASH --global-secondary-indexes IndexName=unitOwnerIndexDev,KeySchema=["{AttributeName=ownerName,KeyType=HASH}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=1,WriteCapacityUnits=1}" --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 --endpoint-url http://localhost:8000

请使用
FilterExpression
按非键属性筛选数据。在上述情况下,
unitID
不是GSI中密钥的一部分

下面的
params
对我来说很好(即结果只有一项)

var params = {
    TableName : table,
    IndexName : "unitOwnerIndexDev",
    KeyConditionExpression : 'ownerName= :hkey',
    FilterExpression : 'unitID = :unitIdVal',  
    ExpressionAttributeValues : {
        ':hkey' : 'owner1',
        ':unitIdVal' : '1'
    }
};