Skip to content

Commit

Permalink
Top 5 frames
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan812 committed Jun 29, 2024
1 parent 97b872a commit 0fd50db
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/nextjs/app/api/analytics/top5frames/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NextResponse } from "next/server";
import Analytics from "~~/model/analytics";
import connectDB from "~~/services/connectDB";

export async function GET() {
await connectDB();
const topFrames = await Analytics.aggregate([
{ $group: { _id: "$frameId", count: { $sum: 1 } } }, // Group by frameId and count documents
{ $sort: { count: -1 } }, // Sort by count in descending order
{ $limit: 5 }, // Limit to top 5 results
]).exec();

return new NextResponse(JSON.stringify(topFrames), {
headers: {
"Content-Type": "application/json",
},
});
}

0 comments on commit 0fd50db

Please sign in to comment.