DynamoDb:查询两个日期之间的项目 [英] DynamoDb: Query items between two dates

查看:86
本文介绍了DynamoDb:查询两个日期之间的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对该查询不太满意,它返回0个项目

I'm not having much luck with this query, it returns 0 items

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();

我在数据库中有一项:

{
  "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-20T02:58:49.710Z介于2017-08-30T03:11:22.627Z和现在。

I would expect 2018-02-20T02:58:49.710Z to fall between 2017-08-30T03:11:22.627Z and now.

您能帮忙查询吗?

推荐答案

您是否尝试过使用。 scan 而不是。 query

Have you tried using .scan instead of .query ?

this.dynamoDB.scan(params, onScan); // scan can do filtering 

function onScan(err, data) {
if (err) {
    console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
} else { 
    //do something with data
}

>请参见步骤4.3:扫描

这篇关于DynamoDb:查询两个日期之间的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆