NodeJS DynamoDb:查询两个日期之间的项目

ar5n3qh5  于 2023-08-04  发布在  Node.js
关注(0)|答案(1)|浏览(74)

我没有太多的运气与此查询,它返回0项

const { Items } = await this.dynamoDb.query({
  TableName: 'exampleTableName',
  IndexName: 'createdDateTime-index',
  KeyConditionExpression: '#createdDateTime BETWEEN :fromDateTime AND :toDateTime AND #status = :status',
  ExpressionAttributeNames: {
    '#status': 'status',
    '#createdDateTime': 'createdDateTime',
  },
  ExpressionAttributeValues: {
    ':fromDateTime': '2017-02-20T01:58:49.710Z',
    ':toDateTime': new Date().toISOString(),
    ':status': 'SUCCESS',
  },
}).promise();

字符串
我在DB中有一个项目:

{
  "id": "fa47003a-983a-4dc3-a87e-ace73ea7e451",
  "createdDateTime": "2018-02-20T02:58:49.710Z",
  "status": "SUCCESS"
}


表:

aws dynamodb create-table \
  --endpoint-url http://localhost:8000 \
  --table-name exampleTableName \
  --attribute-definitions \
    AttributeName=id,AttributeType=S \
    AttributeName=status,AttributeType=S \
    AttributeName=createdDateTime,AttributeType=S \
  --key-schema \
    AttributeName=id,KeyType=HASH \
  --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=10 \
  --global-secondary-indexes \
    IndexName=createdDateTime-index,KeySchema=["{AttributeName=status,KeyType=HASH},{AttributeName=createdDateTime,KeyType=RANGE}"],Projection="{ProjectionType=ALL}",ProvisionedThroughput="{ReadCapacityUnits=10,WriteCapacityUnits=10}"


我预计2018-02- 20 T02:58:49.710Z将落在2017-08- 30 T03:11:22.627Z和现在之间。
你能帮忙查询一下吗?

csga3l58

csga3l581#

我测试了下面的代码,它按预期工作:

const { Items } = await this.dynamoDb.query({
  TableName: 'myTable',
  IndexName: 'myIndex',
  KeyConditionExpression: '#createdDateTime BETWEEN :fromDateTime AND :toDateTime AND #status = :status',
  ExpressionAttributeNames: {
    '#status': 'status',
    '#createdDateTime': 'createdDateTime',
  },
  ExpressionAttributeValues: {
    ':fromDateTime': '2017-02-20T01:58:49.710Z',
    ':toDateTime': new Date().toISOString(),
    ':status': 'SUCCESS',
  },
}).promise();

字符串

相关问题