# mongodump: Failed: error getting database collections: not authorized on db to execute command { listCollections }

**Code:** `mongodump: Failed: not authorized / authentication failed` · **Category:** MongoDB · **Seen on:** MongoDB, Linux

`mongodump` connected but the user isn't allowed to read the data, or authentication didn't happen.

## Meaning

Provide credentials and the right `authSource`: `--uri "mongodb://user:pass@host/db?authSource=admin"`. The user needs `read` (or `backup`) role on the databases. For Atlas use the connection string with a user that has `readAnyDatabase` or specific read roles.

## Common causes

- No credentials passed
- Missing authSource
- User lacks `backup`/`read` role
- Special characters in the password not URL-encoded
- Connecting to the wrong host/port

## Quick fix

1. Use `--uri` with credentials and `authSource`
2. Grant `backup` role: `db.grantRolesToUser("u",[{role:"backup",db:"admin"}])`
3. URL-encode special characters

## Detailed fix by platform

### Linux

1. `mongodump --uri "mongodb://backup:pass@host:27017/?authSource=admin" --gzip --archive=dump.gz`

## How to diagnose

1. **Credentials** — Passed?
2. **Role** — backup/read?
3. **authSource** — admin?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/mongodb/mongodump-authentication-failed)
