Halindra
Halindra•2d ago

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,
});
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()],
},
},
});
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?
1 Reply
Convex Bot
Convex Bot•2d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!

Did you find this page helpful?