Hello,
I’m having an issue with a new Charts dashboard I’ve set up. The dashboard is scheduled to run at 00:30 UTC+1 to avoid peak database usage, but on its first run, all charts failed with a “Cannot retrieve data” error. When I tried to view the dashboard directly on charts.mongodb.com, I got the same error with details “An error occurred while loading data for this chart.”
I’ve attached the dashboard export file for reference. Here’s a quick summary of the charts and what I’ve tried:
- Simple Count Charts: Two of the charts are simple count(_id) queries on collections with 200k and 3.5m documents, respectively. These should be very fast.
- More Complex Charts: The other charts are more intensive, involving a “Table Grouping by a Field” and a “Grouped Bar by an unwound array field” with both using count(_id). These queries use fields that have separate indexes. It seems like Charts aren’t utilising these indexes, or the chart is timing out.
Viewing the Cluster Query Incisights shows the following query for a Number count(_id) chart.
"pipeline": [
{
"$group": {
"_id": {},
"__alias_0": {
"$sum": 1
}
}
},
{
"$project": {
"_id": 0,
"__alias_0": 1
}
},
{
"$project": {
"value": "$__alias_0",
"_id": 0
}
},
{
"$limit": 5000
},
{
"$facet": {
"currentDocs": [
{
"$addFields": {
"noop": 1
}
},
{
"$project": {
"noop": 0
}
}
]
}
},
{
"$project": {
"finalDocs": {
"$cond": {
"if": {
"$gte": [
{
"$size": "$currentDocs"
},
{
"$literal": 1
}
]
},
"then": "$currentDocs",
"else": [
{
"value": {
"$literal": 0
}
}
]
}
}
}
},
{
"$unwind": "$finalDocs"
},
{
"$replaceRoot": {
"newRoot": "$finalDocs"
}
},
{
"$match": {
"$comment": "a8a1324fc05829cca39c168eb5e19b43a7fef17a"
}
}
]
Full query log:
Large collection scan for Number count.json (4.4 KB)
Query log for Grouped Bar chart:
Bar chart array unwind.json (3.6 KB)
Are there any optimisations that can be made to avoid collection scans? Any help or suggestions would be greatly appreciated!
Thanks
Summary Report.json (11.1 KB)