'What is needed to be able to make a backup of mongo database

I am trying to make a backup of mongo database, but I keep getting authentication errors. I gave my user all the privileges I could and I still cannot do a backup:

# mongosh --host 10.1.10.1 --port 27017 -u administrator admin --quiet --eval "db.getUsers();"
Enter password: ************************************
{
  users: [
    {
      _id: 'admin.administrator',
      userId: UUID("52befffa-7fa9-4ab9-9325-3dfdead28f20"),
      user: 'administrator',
      db: 'admin',
      roles: [
        { role: 'userAdminAnyDatabase', db: 'admin' },
        { role: 'restore', db: 'admin' },
        { role: 'readWriteAnyDatabase', db: 'admin' },
        { role: 'root', db: 'admin' },
        { role: 'backup', db: 'admin' }
      ],
      mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
    },
    {
      _id: 'admin.project-12',
      userId: UUID("375a91b7-8c27-4d1d-8d02-ba04faaa94ce"),
      user: 'project-12',
      db: 'admin',
      roles: [ { role: 'readWrite', db: 'project-12' } ],
      mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]
    }
  ],
  ok: 1
}
# mongodump --host 10.1.10.1 --port 27017 -u administrator --archive=test-1 --db=project-12
Enter password:

2022-05-12T18:01:55.677+0200    Failed: can't create session: could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

What am I doing wrong?



Solution 1:[1]

You need to specify the authentication database, for example

mongodump --host 10.1.10.1 --port 27017 -u administrator --authenticationDatabase=admin ...

On mongosh the authentication database defaults to the database you connect. See Authentication failure while trying to save to mongodb

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wernfried Domscheit