DynamoDB查询遇到困难



我试图将头缠绕在AWS DynamoDB周围,并且难以获得记录。如果我的数据库物品看起来像这样:

{
    "id": string (primary)
    "identifier": string
    "project": string
}

我正在尝试使用标识符和项目获得记录:现在我这样做:

const params = {
    TableName: 'MY_TABLE',
    ExpressionAttributeValues: {
        ':identifier': { S : 'Dave' },
        ':project': { S : 'red_squad' },
    },
    KeyConditionExpression: 'identifier = :identifier and project = :project'
}
docClient
    .query(
        params, 
        (err, data) => console.log(err || data)
    )

但是,它告诉我它需要主要键,但是我不适合我的用例。

使用扫描,而不是查询https://docs.aws.amazon.com/awsjavascriptsdk/latest/aws/dynamodb/documentclient.html#scan-property

const params = {
    TableName: 'MY_TABLE',
    ExpressionAttributeValues: {
        ':identifier': { S : 'Dave' },
        ':project': { S : 'red_squad' },
    },
    FilterExpression: 'identifier = :identifier and project = :project'
}
docClient
    .scan(
        params, 
        (err, data) => console.log(err || data)
    )

最新更新