Reputation: 7609
I'm trying to wrap my head around AWS DynamoDB and having trouble getting records. If my db item looks like this:
{
"id": string (primary)
"identifier": string
"project": string
}
I'm trying to get a record using both identifier and project: Right now I'm doing that like this:
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)
)
However it's telling me that it needs the primary key, however I that's not suitable for my use case.
Upvotes: 1
Views: 93
Reputation: 14809
Use a scan, not a query 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)
)
Upvotes: 1