admin管理员组文章数量:1355555
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)'
本文标签: javascriptDynamoDB query with lambda (nodejs) FilterExpression using containsStack Overflow
版权声明:本文标题:javascript - DynamoDB query with lambda (node.js) FilterExpression using contains - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744004414a2574437.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论