23 · 2026

Aggregation Playground

ลองเขียน MongoDB aggregation pipeline กับข้อมูลการเล่นบอร์ดเกม แล้วดูข้อมูลเปลี่ยนไปทีละ stage — engine เขียนเองทั้งหมด รันในเบราว์เซอร์Write a MongoDB aggregation pipeline against board-game play data and watch the documents change stage by stage — a hand-written engine that runs in the browser.

aggregate/engine.ts
// คืนผลหลัง "ทุก" stage ให้ UI ไล่ดูได้export function runPipeline(docs, pipeline) {  const outputs = [];  pipeline.forEach((stage, i) =>    outputs.push(docs = runStage(docs, stage, i)));  return outputs;}
23STAGES7

ทำไมถึงทำ

ใน Boardgame Everyday ผมดูแลส่วนสถิติที่ใช้ aggregation pipeline — ตอนเขียนจริงมักงงว่าข้อมูลหน้าตาเป็นยังไงระหว่างแต่ละ stage เลยทำเครื่องมือที่เห็นผลทุก stage

Engine

  • รองรับ $match ($gt $gte $lt $lte $in $nin $ne $exists $or $and), $group ($sum $avg $min $max $count $first $last $push $addToSet), $sort, $limit, $skip, $project, $count
  • บอกได้ว่า stage ไหนผิดและผิดเพราะอะไร
  • ไม่แก้ข้อมูลต้นฉบับ (immutable) — มี test ตรวจ

การเข้าถึง

  • ผลลัพธ์เป็นตาราง HTML จริง อ่านด้วย screen reader ได้
  • ข้อความ error ผูกกับช่องแก้ไข และประกาศทันที

Why

On Boardgame Everyday I own the stats module, built on aggregation pipelines. When writing them it's easy to lose track of what the documents look like between stages — so this shows every stage's output.

Engine

  • Supports $match ($gt $gte $lt $lte $in $nin $ne $exists $or $and), $group ($sum $avg $min $max $count $first $last $push $addToSet), $sort, $limit, $skip, $project, $count
  • Reports which stage failed and why
  • Never mutates the input — covered by a test

Accessibility

  • Results are real HTML tables that screen readers can navigate
  • Errors are tied to the editor and announced immediately