使用BETWEEN comparisonOperator在DynamoDB中使用ScanFilter

时间:2018-10-16 01:27:08

标签: javascript amazon-web-services filter amazon-dynamodb

我正尝试使用ScanFilter通过dynamoDB过滤日期。 我尝试查看文档,但找不到如何构造JSON格式。 目前我有:

Stuff(Coalesce(' ' + Buyer_Address1, '') + 
      Coalesce(' ' + Buyer_Address2, '') + 
      Coalesce(' ' + Buyer_City, '') + 
      Coalesce(' ' + Buyer_State, '') + 
      Coalesce(' ' + Buyer_ZipFive, '') +
      Coalesce('-' + nullif(Buyer_ZipFour, ''), ''), 1, 1, ''
     ) AS [MailingAddress]

我不确定AttributeValueList中应该包含什么内容,或者我是否必须将日期修改为DynamoDB本身的特定格式。

谢谢

3 个答案:

答案 0 :(得分:0)

根据the ScanFilter AWS docs,将AttributeValueList指定为类型->值映射的数组。

在您的情况下,数组看起来像这样:

"AttributeValueList": [
  {"S": "Wed, 10 Oct 2018 21:09:23 GMT"},
  {"S": "Fri, 12 Oct 2018 21:09:23 GMT"}
]

请注意,the Date type is stored as an S (String) DynamoDB type

答案 1 :(得分:0)

BETWEEN查询中使用FilterExpression中的scan

const AWS = require('aws-sdk');
const documentClient = new AWS.DynamoDB.DocumentClient();


let queryParams = {
  TableName: 'tableName',
  FilterExpression: '#lastModified BETWEEN :startTime AND :endTime',
  ExpressionAttributeValues: {
    ':startTime': '2018-06-26T18:10:00.000Z',
    ':endTime': '2018-06-27T18:10:00.000Z'
  },
  ExpressionAttributeNames: { '#lastModified': 'lastModified' },
  ScanIndexForward: false
};

documentClient.scan(queryParams, function (err, data) {
  if (err) {
    console.log('failure:scan data from Dynamo error', err);
    console.log(err);
  } else {
    console.log('success:scan data from Dynamo data');
    console.log(data);
  }
});

答案 2 :(得分:0)

好像我需要使用BETWEEN比较运算符,并在相同数据类型的数组中提供逗号分隔的值:

 "ScanFilter": {
      "lastModified": {
        "ComparisonOperator": "BETWEEN",
        "AttributeValueList": [
            "Wed, 10 Oct 2018 00:02:59 GMT",
            "Wed, 10 Oct 2018 23:46:34 GMT"
        ]
      }
    }