interface Attendee {
_id: ObjectId;
name: string;
email: string;
conferenceId: ObjectId;
talks: ObjectId[];
ticketTier: "standard" | "vip";
}
interface Talk {
_id: ObjectId;
title: string;
speakerId: ObjectId;
durationMin: number;
schedule: {
track: "main" | "workshop" | "lightning";
room: string;
startsAt: Date;
};
}
const report = await attendees.aggregate([
{ $match: { tier: "vip" } },
{ $lookup: {
from: "talk",
localField: "talks",
foreignField: "_id",
as: "talkDocs"
} },
{ $project: {
name: 1,
talkCount: { $size: "$talkDocs" },
mainStageTalks: { $size: { $filter: {
input: "$talkDocs",
cond: { $eq: ["$$this.schedule.tracks", "main"] }
} } }
} },
{ $group: {
_id: "$conferenceId",
total: { $sum: "$talkCount" }
} },
{ $sort: { total: -1 } }
]).toArray();