I'm having the below data in dynamo DB
id category value rule
1 a 5 1
2 b 5 1
3 c 5 1
4 a 5 2
5 b 5 2
6 a 2 3
7 b 2 3
8 a 3 4
9 b 3 4
10 c 2 4
11 d 2 4
12 b 5 5
13 c 5 5
Here my target is as below.
- First scan the table and get the
rule
with size2
. once I get that rule, check if it has onlya
andb
in category. Ignore the rest.
Here is my current query.
var array=["a","b"];
for (index = 1; index <= 5; ++index) {
console.log(index);
var params1 = {
TableName: "MyCatTable",
FilterExpression: "#rule=:rule",
ExpressionAttributeNames: {
"#rule": "rule"
},
ExpressionAttributeValues: {
":rule": String(index)
}
};
results.push(dynamodb.scan(params1).promise().then(function (data) {
if (data.Items.length == 2 && (array.indexOf(data.Items[0].category) >= 0)) {
var uw = data.Items;
return uw;
}
}));
}
return Promise.all(results);
}).then((data) => {
var res;
console.log("----------------------");
console.log(data);
})
when I run this it is returning me the rules 2
, 3
and 5
. But I need only 2
and 3
. since 5
has b
and c
instead of a
and b
.
or is there any other way of filtering out the json response that I get?
please let me know where am I going wrong and how can I fix this.
Thanks