How to Fix MongoDB Error 140 (InvalidSSLConfiguration)
You see mongodb error 140 when a database node or client has broken SSL settings. You fix this InvalidSSLConfiguration error by aligning your key files, trust chains, and transport rules. Database security relies on valid encryption files during startup and login. If one file is missing or unreadable, the service refuses to run. Teams must find the bad file path or mismatch without turning off security checks. What causes mongodb error 140 in your cluster The database engine throws code 140
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 140 when a database node or client has broken SSL settings. You fix this InvalidSSLConfiguration error by aligning your key files, trust chains, and transport rules.
Database security relies on valid encryption files during startup and login. If one file is missing or unreadable, the service refuses to run. Teams must find the bad file path or mismatch without turning off security checks.
What causes mongodb error 140 in your cluster
The database engine throws code 140 when it maps to the official InvalidSSLConfiguration state. This happens when the server starts up or when a client tries to log in.
First, the certificate or key file might be missing from the disk. Sometimes the file is there, but the database user lacks OS read permissions. If the process cannot read the file, it stops right away.
Second, the public certificate and private key might not match each other. This often happens after a routine certificate renewal goes wrong. An admin might update the public file but leave the old key file in place.
Third, the root authority file might be absent or formatted the wrong way. Cluster nodes need this authority file to check peer certificates during internal talks. If a node requires peer checks without a root file, it triggers code 140.
Finally, the file itself might have syntax errors or extra blank lines. Certificates must use standard text blocks with clear start and end markers. Any bad text inside the file breaks the parser and stops the service.
How to diagnose and fix InvalidSSLConfiguration safely
Start by reading the server log lines right above the error 140 message. The engine writes the exact reason why the SSL setup failed in those lines. You will see if the cause is a missing path, a permission block, or a bad key.
Next, check the file permissions on every host in your database cluster. Make sure the system account that runs the database owns the certificate files. Restrict read rights so only that service account can open the private key.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Then, verify that your public certificate matches its private key and root chain. Check the expiration dates on all files in the chain as well. Replace any expired or mismatched files with fresh copies from your certificate authority.
Never fix this error by turning off SSL or skipping peer checks in production. Leaving traffic open on the network exposes your data to serious risk. Fix the broken file path or bad key instead of dropping your defense.
Securing database roles during incident repair
When engineers inspect a cluster during an outage, they still need strict role limits. MongoDB grants access through role-based rules on defined resources down to the collection level. You should give responders the smallest role needed to check cluster health.
For data checks, the built-in read role grants read access to all non-system collections. It allows safe actions like find, listCollections, listIndexes, dbStats, collStats, and changeStream. It blocks risky actions such as insert, update, remove, or dropCollection.
Only grant the readWrite role when an engineer must change data to fix an issue. This role adds actions like insert, update, remove, createIndex, dropIndex, and dropCollection. Note that Atlas users and self-hosted users have different built-in roles from the same actions.
Even with a read role, query results can hold private user details. Adding data masking in your access layer rewrites matched fields like emails and phone numbers. It also rewrites card numbers and national IDs in results to keep data safe.
Inspect MongoDB wire traffic in flight
Built-in MongoDB roles govern collection access at setup time. They cannot score command risk per call or mask sensitive document values on the fly. By design, hoop.dev sits inline in the MongoDB protocol next to your server as a sidecar for your MongoDB. On every production command from mongosh, drivers, or AI agents, hoop.dev decides whether to pass, mask, block, or hold it for human review.
First, hoop.dev guardrails block bad deletes, drops, and write pipelines or hold them for approval. Next, hoop.dev data masking rewrites sensitive values in returned documents in memory and logs each decision. Explore the repo on GitHub.
Frequently asked questions
What does error code 140 mean in MongoDB?
Error code 140 is the official InvalidSSLConfiguration error in the database engine. It means the server or client has missing, unreadable, or mismatched SSL certificate settings.
Can I fix InvalidSSLConfiguration by turning off SSL checks?
Turning off SSL removes the error, but you should never do this in production. Always fix the file permissions, key match, or trust chain so traffic stays encrypted.
Does error 140 affect database user roles after login?
No, error 140 happens at the transport layer before a user logs in. Once you fix the SSL files, normal database roles and collection permissions work as expected.
Related guides
In this post