server: vaa counts

This commit is contained in:
Evan Gray 2022-09-29 13:40:07 +00:00
parent 559f873c25
commit 9bcf8f0283
1 changed files with 42 additions and 0 deletions

View File

@ -93,6 +93,48 @@ app.get("/api/vaas-sans-pythnet", async (req, res) => {
});
});
app.get("/api/vaa-counts", async (req, res) => {
const database = mongoClient.db("wormhole");
const collection = database.collection("vaas");
const cursor = await collection.aggregate([
{
$bucket: {
groupBy: "$_id",
boundaries: [
"1/",
"10/",
"11/",
"12/",
"13/",
"14/",
"15/",
"16/",
"18/",
"2/",
"26/",
"3/",
"4/",
"5/",
"6/",
"7/",
"8/",
"9/",
],
default: "unknown",
output: {
count: { $sum: 1 },
},
},
},
]);
const result = await cursor.toArray();
if (result.length === 0) {
res.sendStatus(404);
return;
}
res.send(result);
});
/*
* Observations
*/