如何根据特定索引的 rangeKey 而不是默认的 rangeKey 对 Dynamoose 中的查询结果进行排序?

问题描述 投票:0回答:1

使用 Dynamoose 库查询 DynamoDB 时,结果默认按模型架构中定义的 rangeKey 排序。但是,当我使用不同的索引时,结果应该按该索引中定义的 rangeKey 排序,但它们仍然按默认的 rangeKey 排序。这个问题有什么解决办法吗?

const dynamoose = require("dynamoose");

const schema = new dynamoose.Schema(
  {
    a: {
      type: Number,
      required: true,
      hashKey: true,
    },
    b: {
      type: String,
      required: true,
      rangeKey: true,  // default sort
    },
    c: {
      type: String,
      required: true,
      index: {
        global: false,
        name: "c-index",
        rangeKey: "c",  // I would like to receive the results sorted by this column.
        project: true,
        throughput: "ON_DEMAND",
      },
    }
  },
);
const result = await sometingModel.query("a")
.eq(a)
.using("c-index")
.where("c")
.ge(c)
.all()
.exec();

我想接收根据 c 列排序的值,但结果显示为根据 b 列排序。如何获得根据 c 列排序的值?

sorting amazon-dynamodb dynamoose
1个回答
0
投票

DynamoDB 始终根据目标表/索引的排序键返回结果。

虽然我不能代表 Dynamoose,但以下是我的建议:

  1. 检查通过线路发送到 DynamoDB 的 http 请求,确保它包含索引名称。
  2. 检查通过网络发送的响应,在反序列化之前检查顺序。
  3. 如果问题出在 Dynamoose 上,请在他们的 Guy 中提出问题
  4. 如果 DynamoDB 似乎存在问题,请回到这里来找我。
© www.soinside.com 2019 - 2024. All rights reserved.