node.js – How to search array values in dynamoDB
I have data with status [‘available’, ‘pending’, ‘sold].
I’d like choose any of them(It can be one to three). and I want to search with that values.
Like for example if I choose [‘available’, ‘pending’], I want both items to show.
And my dynamoDB table Partition key is id but I create status-index key(global secondary index).
this is my code.
I’ve searched all over but cant find out how..
please help
async function getPetByStatus(status) {
let statusValues = status
let statusObject = {};
let index = 0;
statusValues.forEach(function(value) {
index++;
let statusKey = ":statusvalue"+index;
statusObject[statusKey.toString()] = value;
});
const params = {
TableName : "pet",
IndexName: "status-index",
FilterExpression : "status IN ("+Object.keys(statusObject).toString()+ ")",
ExpressionAttributeValues : statusObject
};
return await dynamo.scan(params).promise().then((response) => {
return buildResponse(200, response);
}, (err) => {
console.error("Error", err);
});
}
Read more here: Source link