Reputation: 1
When querying DynamoDB using the Dynamoose library, the results are by default sorted by the rangeKey defined in the model schema. However, when I use a different index, the results should be sorted by the rangeKey defined in that index, but they are still sorted by the default rangeKey. What would be the solution to this problem?
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();
I want to receive values sorted based on column c, but the results are shown sorted based on column b. How can I get the values sorted according to column c?
Upvotes: 0
Views: 192
Reputation: 19683
DynamoDB always returns the results based on the sort key of the target table/index.
While I can't speak for Dynamoose, here is my suggestions:
Upvotes: 0