## TL;DR

For "MongoServerError: bad auth : Authentication failed.": add authSource=admin explicitly. If the network were the problem you would see a timeout instead.

```text
MongoServerError: bad auth : Authentication failed.
```

## Steps

1. Full text looks like: `MongoServerError: bad auth : Authentication failed.` This is always credentials, never the network. If the network were the problem you would see a timeout instead.

2. Correct the piece that is wrong, update the stored secret, and re-run the startup ping. Do not "fix" it by widening the IP access list or recreating the cluster.

## When to use

You are seeing this: Full text looks like: MongoServerError: bad auth : Authentication failed. Use this skill when you run into "Atlas error: bad auth, authentication failed (code 18)".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
