HalindraH
Convex Community4mo ago
1 reply
Halindra

Aggregate component third prefix seems to be ignored?

I’m using the convex TableAggregate component like this:

export const aggregateRemainingAmount = new TableAggregate<{
  Key: [Id<"students">, number, number];
  DataModel: DataModel;
  TableName: "bills";
}>(components.aggregateBillRemainingAmount, {
  sortKey: (bill) => [
    bill.studentId,
    bill.academicYearStartDate,
    bill.startDate,
  ],
  sumValue: (bill) => bill.remainingAmount,
});


When I run the query:

await aggregateRemainingAmount.sum(ctx, {
  bounds: {
    lower: {
      inclusive: true,
      key: [
        student._id,
        Number.NEGATIVE_INFINITY,
        Number.NEGATIVE_INFINITY,
      ],
    },
    upper: {
      inclusive: true,
      key: [student._id, Date.now(), Date.now()],
    },
  },
});


I want the sum of remainingAmount for a student:
- across all academic years up until now,
- but only including bills where startDate has already passed.

The issue is: it looks like the third prefix (bill.startDate) is being ignored in the bounds comparison.

👉 Is this expected behavior in convex aggregates? If not, how can I correctly structure my bounds so that bill.startDate is actually respected?
Was this page helpful?