I have a table in dynamoDB called 'Contributors'. I have a primary composite key where the hash key is 'UserId' and the sort key is 'NoteId'. I want to query for all the items belonging to a particular hashkey.
Now if I use aws-cli, following command works:
aws dynamodb query \
--table-name Contributors \
--key-condition-expression 'UserId = :UserId' \
--expression-attribute-values '{
":UserId": {"N":"2"}
}'
But when I write the query in Node.js, neither of the below 2 param objects work:
var params = {
TableName: "Contributors",
KeyConditionExpression: "#UserId = :UserId",
ExpressionAttributeNames: {
"#UserId": "UserId"
},
ExpressionAttributeValues: {
":UserId": { "N": "2" }
}
};
OR this:
var params = {
TableName: "Contributors",
KeyConditionExpression: "#UserId = :UserId",
ExpressionAttributeNames: {
"#UserId": "UserId"
},
ExpressionAttributeValues: {
":UserId": "2"
}
};
I get the following error:
ValidationException: One or more parameter values were invalid: Condition parameter type does not match schema type
What should be the correct param object?