如何使用FilterExpression和两个未索引字段查询DynamoDB表

2024-04-20 03:23:25 发布

您现在位置:Python中文网/ 问答频道 /正文

在DynamoDB表中country是主键createdAt是排序键,我想查询countryUSA、城市是San Francisco、街道不是Market street的项目。但是,即使一个表中有多个项目,query命令也不会返回结果。我在这里做错了什么:

import { DynamoDB } from 'aws-sdk';
db = new DynamoDB.DocumentClient({ apiVersion: '2012-08-10', service: new DynamoDB() })

 params = {
  TableName: 'my-table',
  IndexName: 'country-createdAt',
  KeyConditionExpression: 'country = :country',
  FilterExpression: 'street <> :street and city = :city',
  ExpressionAttributeValues: {
    ':country': 'USA',
    ':street': 'Market street',
    ':city': 'San Francisco'
  }
}

let output = await db.query(params);

结果如下:

{ Items: [], Count: 0, ScannedCount: 200 }