I have the following table:
export const profileTags = defineTable({
tag: v.string(),
profile: v.id("profiles"),
})
.index("by_tag", ["tag"])
.index("by_tag_and_profile", ["tag", "profile"]);
I want to be able to get a count of how many profiles have a specific tag, for example I want to be able to query the tag "Halloween" and get a count that 120 profiles have that specific tag. I want to use the aggregate component. This is my table implementation:
import { TableAggregate } from "@convex-dev/aggregate";
import { DataModel } from "../../_generated/dataModel";
import { components } from "../../_generated/api";
export const profileTagsStats = new TableAggregate<{
Namespace: null; // No namespace since we want to compare across all profiles
Key: [string]; // [favoritedCount, profileId] for sorting
DataModel: DataModel;
TableName: "profileTags";
}>(components.aggregateProfileTags, {
namespace: () => null, // Global namespace to compare all profiles
sortKey: (doc) => [doc.tag], // Sort by favoritedCount
sumValue: (doc) => 1 // Sum the favoritedCount values
});
First is this TableAggregate correct for what I need? Also, how would I backfill this?