MongoDB 3.2 – server returned error on SASL authentication step: Authentication failed.

MongoDB 3.2 – server returned error on SASL authentication step: Authentication failed.

This issue will happen to all MongoDB tools (mongo, mongodump, mongotop, mongostat). However, I encounter the issue while using mongotop.

#mongotop --host=192.168.56.104:27017 -u username -p "THIS1sR3tard3d!!" --authenticationDatabase=admin 5
mongotop --host=192.168.56.104:27017 -u superuser -p "THIS1sR3tard3dmongostat --host=192.168.56.104:27017 --username=user --password='THIS1sR3tard3d!!' --authenticationDatabase=admin " --authenticationDatabase=admin 5
2016-11-17T17:43:59.523+0000 Failed: error connecting to db server: server returned error on SASL authentication step: Authentication failed.

The issue is with the password with special characters. Apparently, even when you double quote a password, it still doesn’t ignore the special characters. t doesn’t help the situation when the error message is really vague.

#mongotop --host=192.168.56.104:27017 -u username -p 'THIS1sR3tard3d!!' --authenticationDatabase=admin 5

To solve the issue, simply single quote the password field đŸ™‚

Update:

Apparently, escaping the special characters using single quote works too!

mongo -u username -p '1234'@''@'' --authenticationDatabase admin <ip>:port/db

Hope this helps

Regards,
Wei Shan

5 thoughts on “MongoDB 3.2 – server returned error on SASL authentication step: Authentication failed.”

  1. Hi Shan,

    Any idea why “No candidate servers found” comes, I’m trying to make a connection with Atlas server and getting this.

    Thanks in advance.

Leave a comment