How to Fix MongoDB Error 295 (InvalidHeartBeatFrequency)
You get mongodb error 295 when a client or node sets an invalid heartbeat interval. To fix this InvalidHeartBeatFrequency error, change the heartbeat frequency in your connection or cluster settings. MongoDB uses heartbeats to check if cluster nodes and client links stay alive. Every node and driver must use a valid time value for these health checks. When a value falls outside the allowed range, the database rejects the request. It then returns code 295 with the name InvalidHeartBeatFrequency.
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 get mongodb error 295 when a client or node sets an invalid heartbeat interval. To fix this InvalidHeartBeatFrequency error, change the heartbeat frequency in your connection or cluster settings.
MongoDB uses heartbeats to check if cluster nodes and client links stay alive. Every node and driver must use a valid time value for these health checks. When a value falls outside the allowed range, the database rejects the request. It then returns code 295 with the name InvalidHeartBeatFrequency.
What causes mongodb error 295 in your cluster
Two main things trigger mongodb error 295 in a live system. First, an app driver might pass a bad heartbeat value in its connection string. If the number is too small, negative, or malformed, the driver or server stops.
Second, a cluster admin might edit replica set settings with a bad interval value. Nodes need regular signals to know which server is the primary node. A bad interval breaks this check. If heartbeats run too fast, they flood the network with extra traffic. If they run too slow, the cluster fails to spot dead nodes in time. MongoDB blocks bad values right away to protect cluster health.
Typos in deployment scripts often cause this failure during a release. Teams sometimes mix up milliseconds and seconds when they write new settings. A script might also pass an empty string or zero by mistake. When the database reads that setting, it throws the InvalidHeartBeatFrequency error and blocks the change.
How to check and fix InvalidHeartBeatFrequency safely
Start your check by reading the app logs and database server logs. Find out if the error comes from a client app or a cluster command. If an app log shows code 295, check the connection settings for that service. Look at the heartbeat frequency value and set it within the allowed driver limits. Test the new setting in a staging setup before you push it to production.
If the error happens during a cluster update, inspect the replica set config document. You do not need full write rights to check the current state. MongoDB grants access through role-based rules down to the collection level. Use a read-only account to inspect cluster status and log data first. For example, the built-in read role grants actions like find, dbStats, and collStats. It does not allow insert, update, remove, or dropCollection actions.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Once you spot the bad heartbeat value, plan a safe update. Have a peer review the exact time unit before you run the change. Do not grant permanent admin rights to fix a single setting. Use a scoped role that only allows the needed admin action for that moment. Also, make sure your team masks sensitive data like emails or card numbers in logs. Masking rewrites matched fields in results while you read query outputs during a fix.
How to prevent heartbeat config errors in production
You can stop code 295 before it hits your live database. Store all connection strings and cluster settings in version control. Run automated checks on these files before any deploy starts. Check that all time values are positive numbers within safe bounds.
Keep production database roles tight so scripts cannot push unreviewed changes. Separate read roles from write roles across your whole team. When engineers only have read rights by default, a bad script cannot break cluster settings. Require a second person to approve any command that alters replica set timings. This simple step catches typos in heartbeat settings before they cause downtime.
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
What does MongoDB error code 295 mean?
Error 295 has the official name InvalidHeartBeatFrequency in MongoDB. It means a client driver or cluster config used an invalid heartbeat time value.
Can a client app trigger InvalidHeartBeatFrequency?
Yes, a client app can trigger it if its connection settings pass a bad interval. Fix the heartbeat value in the app settings and restart the service.
Do I need write permissions to diagnose error 295?
No, you can check logs and status with a read-only role first. You only need higher privileges when you apply the fixed cluster setting.
Related guides
In this post