How to Fix MongoDB Error 435 (QueryStatsFailedToRecord)
You see mongodb error 435 when the database engine fails to save internal query metrics. You fix this QueryStatsFailedToRecord failure by freeing memory and checking internal storage state. Database teams rely on query stats to spot slow reads and heavy load. When the stats subsystem hits a limit, the engine logs code 435. Knowing why this failure happens helps your team fix it fast without risking data. What causes mongodb error 435 in your cluster The official name for mongodb error 435 is
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You see mongodb error 435 when the database engine fails to save internal query metrics. You fix this QueryStatsFailedToRecord failure by freeing memory and checking internal storage state.
Database teams rely on query stats to spot slow reads and heavy load. When the stats subsystem hits a limit, the engine logs code 435. Knowing why this failure happens helps your team fix it fast without risking data.
What causes mongodb error 435 in your cluster
The official name for mongodb error 435 is QueryStatsFailedToRecord. The database triggers this code when its internal stats store cannot write a new record. Memory pressure is the most common root cause during traffic spikes.
Every distinct query shape takes up a small amount of memory in the buffer. If an app sends thousands of unindexed query shapes, the stats store fills up fast. The engine may also fail to record stats if an internal lock times out.
High disk load or slow storage can delay background flushes in the cluster. When the engine prioritizes main data writes over metrics, it drops the stats update. It then throws QueryStatsFailedToRecord so operators know metric collection had a gap.
In some cases, a sudden burst of ad-hoc queries from analysts triggers the problem. Each unique filter forces the engine to track a new metric entry. That flood can push the internal store past its safe memory limit.
How to diagnose and fix QueryStatsFailedToRecord safely
Start your check by reviewing server logs around the time of the error. Look for memory warnings, high lock wait times, or spikes in open client sessions. Check if a new app release started sending dynamic query shapes without fixed structures.
When you check the cluster, use a least-privilege role for your diagnostic user. MongoDB grants access through role-based authorization on a specific database down to the collection level. The built-in read role grants actions like find, listCollections, listIndexes, dbStats, and collStats.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
That read role covers all non-system collections without allowing insert, update, remove, or dropCollection actions. Do not grant full admin rights or the readWrite role just to inspect query stats. Keeping diagnostic users on read-only roles prevents accidental data edits during an incident.
To clear the error, reduce the number of unique query shapes hitting the database. Ask app teams to group similar filters and remove noisy ad-hoc queries. If memory is full, scale up node RAM or lower the rate of diagnostic polling.
Preventing repeat query stats failures in production
Long-term stability depends on controlling who and what runs queries against production nodes. Unbounded queries from developer laptops often flood the stats buffer and cause code 435. Set clear rules for how engineers run diagnostic reads on live collections.
Keep self-hosted roles and MongoDB Atlas user roles scoped to only needed collections. Both deployment types build roles from the same set of privilege actions. When you limit who can run broad scans, the stats engine stays healthy under load.
Also protect sensitive fields when engineers run read queries to inspect slow workloads. Data masking can rewrite matched fields like emails, phone numbers, card numbers, and national IDs. This keeps diagnostic checks safe while your team tunes query shapes and memory use.
Add command guardrails and field masking beside MongoDB
Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.
Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.
Frequently asked questions
Does mongodb error 435 mean my main database write failed?
No, QueryStatsFailedToRecord means the engine failed to save internal metrics about a query. Your main read or write operation can still finish while the stats recorder drops an entry. You should still check memory and load so the server stays stable.
Which role should I use to inspect database stats safely?
Use the built-in read role on the target database when checking collection and database stats. It allows dbStats, collStats, listIndexes, and find without permitting insert, update, or remove actions. This keeps your check safe from accidental writes.
Can ad-hoc developer queries trigger QueryStatsFailedToRecord?
Yes, many unique ad-hoc queries create new shapes that fill the internal stats store. When too many shapes arrive at once, the engine can fail to record new metrics. Limiting direct ad-hoc query spikes helps stop the error from coming back.
Related guides
In this post