Can't create backup mongodump with --db. Authentication failed

Vladislav Orillo picture Vladislav Orillo · Aug 13, 2015 · Viewed 57.2k times · Source

When I create backup of all databases in MongoDB (version 3):

mongodump --username bacUser --password 12345

It's OK. But when I try to create backup of a selected db:

mongodump --username bacUser --password 12345 --db test

It gives me this error:

Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

Answer

Vladislav Orillo picture Vladislav Orillo · Aug 14, 2015

work with this:

--authenticationDatabase admin

mongodump and mongorestore commands need the name of database where mongodb user's credentials are stored. (thanks @Zubair Alam)