仅在DynamoDB中使用分区键进行查询

时间:2019-05-27 14:32:01

标签: node.js amazon-dynamodb serverless

我试图仅使用分区键查询表,而忽略排序键,但没有任何项目。

我的全局二级索引如下所示: enter image description here

我的桌子看起来像这样: enter image description here

这是我的查询:

const params = {
  ExpressionAttributeValues: {
    ':app': 'app',
  },
  IndexName: 'glc-development-gsi1',
  KeyConditionExpression: 'sk = :app',
  TableName: this.tableName,
};
return new Promise((resolve, reject) => {
  this.client.query(params, (err, data) => {
    console.log(data);
    if (err) {
      reject(err);
    } else {
      resolve(data);
    }
  });
});

根据我已阅读的所有文档以及此处的其他问题,这应该可以工作,我不明白为什么不这样做。来自我的索引的扫描也为空。

1 个答案:

答案 0 :(得分:0)

终于找到了我的解决方案。仅当定义了分区键和排序键时,DynamoDB才会将数据存储在索引中,因此索引一直都是空的。查询很好。