使用 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 列排序的值?
DynamoDB 始终根据目标表/索引的排序键返回结果。
虽然我不能代表 Dynamoose,但以下是我的建议: