# Docker: MongoServerError: Authentication failed — after changing MONGO_INITDB_ROOT_PASSWORD

**Code:** `MONGO_INITDB_ROOT_USERNAME ignored (data volume exists)` · **Category:** MongoDB · **Seen on:** MongoDB, Docker

The official Mongo image creates the root user only on the very first start with an empty data directory; changing env vars later has no effect.

## Meaning

Env vars `MONGO_INITDB_ROOT_*` and scripts in `/docker-entrypoint-initdb.d` run only when `/data/db` is empty. Remove the volume (`docker compose down -v`) for a fresh init in dev, or create/update users manually with `db.createUser` / `db.changeUserPassword`.

## Common causes

- Persistent volume already initialised
- Password changed in compose later
- initdb scripts not re-run
- authSource mismatch
- User created in another database

## Quick fix

1. Dev: `docker compose down -v && docker compose up -d`
2. Prod: `db.changeUserPassword("root","new")` in mongosh
3. Check `authSource=admin`

## Detailed fix by platform

### Docker

1. `docker compose exec mongo mongosh -u root -p --authenticationDatabase admin`

## How to diagnose

1. **Volume** — Existing data?
2. **Init** — Scripts run?
3. **authSource** — admin?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/docker-mongo-init-credentials-ignored-existing-volume)
