Here is the table structure. In posts column it is a list of strings
So I been reading and trying to use filterExpression with 'contains'. What documentation said in node.js just need to use a CONTAINS b where a can be a list and b for me is a string I am searching for.
var db = new doc.DynamoDB();
var params = {
TableName: "WIT_Search",
KeyConditionExpression: "#type = :tag and #key between :start AND :end",
FilterExpression: "#tag contains :post",
ExpressionAttributeNames: {
"#type": "type",
"#tag": "posts",
"#key": "key",
},
ExpressionAttributeValues: {
":tag": "tag",
":start": tag+"_",
":end": tag+"_999",
":post": postID
}
};
console.log(params);
db.query(params, function(err, data) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log("Query succeeded.");
console.log('Count =',data.Items.length);
if (data.Items.length > 0){
console.log("post exists in tag");
}else{
console.log("post doesnt exist in tag");
}
}
});
Whenever I do testing it gives me this message:
Unable to query. Error: {
"message": "Invalid FilterExpression: Syntax error; token: \"contains\", near: \"#tag contains (\"",
"code": "ValidationException",
}
The weird thing on AWS Console it works without the problem, just using in lambda with node.js it gives this error.
Here is the table structure. In posts column it is a list of strings
So I been reading and trying to use filterExpression with 'contains'. What documentation said in node.js just need to use a CONTAINS b where a can be a list and b for me is a string I am searching for.
var db = new doc.DynamoDB();
var params = {
TableName: "WIT_Search",
KeyConditionExpression: "#type = :tag and #key between :start AND :end",
FilterExpression: "#tag contains :post",
ExpressionAttributeNames: {
"#type": "type",
"#tag": "posts",
"#key": "key",
},
ExpressionAttributeValues: {
":tag": "tag",
":start": tag+"_",
":end": tag+"_999",
":post": postID
}
};
console.log(params);
db.query(params, function(err, data) {
if (err) {
console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
} else {
console.log("Query succeeded.");
console.log('Count =',data.Items.length);
if (data.Items.length > 0){
console.log("post exists in tag");
}else{
console.log("post doesnt exist in tag");
}
}
});
Whenever I do testing it gives me this message:
Unable to query. Error: {
"message": "Invalid FilterExpression: Syntax error; token: \"contains\", near: \"#tag contains (\"",
"code": "ValidationException",
}
The weird thing on AWS Console it works without the problem, just using in lambda with node.js it gives this error.
Share Improve this question asked Jul 19, 2017 at 14:21 Ivars AkmentinsIvars Akmentins 551 gold badge2 silver badges7 bronze badges1 Answer
Reset to default 8Here is the correct syntax.
FilterExpression : 'contains (#tag, :post)'