我正在DynamoDB表上执行扫描操作,然后过滤结果以使其在NODE.js中的两个日期之间具有项目
DynamoDB表的数据格式如下:
{
TableName: tableName,
Item: {
"visitorID": visitorIDq, // Primary Key
"dateID": dateTime, // What I am filtering the scan for
"visitorName": "END OF Q",
"employeeName": "END OF Q",
"comments": "END OF Q"
}
当前代码:
var date1 = String(threeMonths); // milliseconds since epoch - 3 months in milliseconds
var date2 = String(dateTime); // milliseconds since epoch aka now
var params2 = {
TableName: tableName,
FilterExpression: "dateID BETWEEN :date1 and :date2",
ExpressionAttributeValues: {
":date1": { "S": date1},
":date2": { "S": date2}
}
};
我收到此错误:
错误无法扫描表。错误JSON:{“ message”:“无效 FilterExpression:运算符或函数的操作数类型错误; 运算符或函数:BETWEEN,操作数类型:M“,” code“: “ ValidationException”,“时间”:“ 2019-07-06T02:00:44.569Z”,
“ requestId”:“ REQUESTID1294743204701HHH443”,“ statusCode”:400,
“ retryable”:否,“ retryDelay”:26.7865000058784}
经过一些互联网搜索之后,我有点卡住了,没有真正在节点中找到其他遇到此问题的人。有什么想法吗?
由于某种原因,Stack Overflow告诉我这主要是代码。我认为我在解释它和提供细节方面做得很好。这是占位符文本,因为我是tryna帖子。它仍在发生。细节。细节。详细信息。
答案 0 :(得分:0)
正确的分辨率:
var dateID = String("\""+ threeMonths + "\""); // var for time in milliseconds, stringifying
var params2 = {
ExpressionAttributeValues: {
':msID' : dateID
},
FilterExpression: "dateID >= :msID", // dateID column in DDB is greater than epoch - 3 months
TableName: "Visitor"
};
JSON.stringify(params2); //params are stringified here for the scan
特别是:
ExpressionAttributeValues: {
':msID' : "15666767546459" // or whatever value you are comparing, the above resolution has dateID there because its a var getting current time
}