Analytics Dashboards
Analytics dashboards — for revenue, product usage, SLOs, marketing funnels — are the third-most-common workload on MongoDB.
Introduction
Analytics dashboards — for revenue, product usage, SLOs, marketing funnels — are the third-most-common workload on MongoDB. With the aggregation framework, $facet, time-series collections and Atlas Charts, you can render rich dashboards directly off operational data.
This lesson shows the shape of a real analytics dashboard pipeline and the operational tricks that keep it sub-second: pre-aggregation with $merge, analytics-tagged secondaries, and time-series buckets.
Learning objective: Apply Analytics Dashboards correctly in a TechLearningPRO MongoDB workload — with clear data-model choices, safe writes, and failure modes you can explain in review.
Treat every example as production-shaped MongoDB: explicit projections, indexes that match the access path, and Atlas-safe defaults. Prefer mongosh / Node driver shapes used in SaaS backends.
Purpose of this lesson
Apply Analytics Dashboards correctly in a TechLearningPRO MongoDB workload — with clear data-model choices, safe writes, and failure modes you can explain in review.
Understanding the topic
The dashboard performance stack:
- $facet — multiple aggregations in one round-trip; one query renders the whole dashboard.
- $merge into rollup collection — recompute every 5 min; dashboards query rollups, not raw events.
- Time-series collections for metrics — automatic bucketing & 10×+ compression.
- Analytics secondaries — heavy reads never touch the primary.
- Atlas Charts — built-in BI tool, no extra license, embeds via signed URL.
Step-by-step explanation
- State when Analytics Dashboards is the right MongoDB tool versus an alternative.
- Map the diagram boxes to driver, mongod, WiredTiger, and your collection.
- Run the smallest correct mongosh / driver example against a TechLearningPRO learners collection.
- Name two failure modes (missing index, bad shard key, unbounded scan) and how you detect them.
Informative example
Dashboard pipeline — KPIs, time-series, breakdowns in one $facet:
db.events.aggregate([{ $match: { tenantId, ts: { $gte: from, $lt: to } } },{ $facet: {kpis: [{ $group: { _id: null,users: { $addToSet: "$userId" },events: { $sum: 1 },revenue: { $sum: "$amount" } } }],perDay: [{ $group: { _id: { $dateTrunc: { date: "$ts", unit: "day" } },count: { $sum: 1 }, revenue: { $sum: "$amount" } } },{ $sort: { _id: 1 } }],topCountries: [{ $group: { _id: "$country", n: { $sum: 1 } } },{ $sort: { n: -1 } }, { $limit: 10 }]} }], { readPreference: { mode: "secondary", tags: [{ nodeType: "ANALYTICS" }] } });
Real-world use
Forbes' editorial dashboard, Bosch's IoT fleet view, and many fintech "deal of the day" panels run on this exact pattern — $facet + analytics secondaries + 5-minute rollups.
Security implications
MongoDB is a trust boundary. Drivers must not interpolate untrusted input into query operators.
- Never build queries by concatenating user strings into operator objects.
- Use least-privilege Atlas database users; apps should not have root.
- Enable TLS and avoid exposing mongod on public networks.
Best practices
- Pre-aggregate to a rollup collection on a cron — dashboards must not run heavy pipelines on every refresh.
- Pin BI traffic to analytics-tagged secondaries with
readPreference + tags. - Time-series collections for metrics; never store raw points in a regular collection.
- Cap dashboard query
maxTimeMSso one slow query cannot starve the cluster.
Common mistakes
- Unbounded
find({})/ aggregation without an early$match. - Missing indexes on hot equality/range predicates.
- Embedding unbounded arrays that approach the 16MB document limit.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhat is Analytics Dashboards and when do you use it?+
Answer
2IntermediateQuestionHow would you verify Analytics Dashboards is working in production?+
Answer
3AdvancedQuestionWhat breaks if you misuse Analytics Dashboards?+
Answer
Hands-on exercise
Hands-on drill:
- Implement the smallest correct example for Analytics Dashboards on a learners/orders-like collection.
- Capture
explain('executionStats')and confirm an index was used when expected.
Summary
Analytics Dashboards is a production MongoDB skill: model for your read path, prove it with explain(), and ship with indexes and least-privilege roles.