2
votes

I followed the instructions here for setting up users...

Then from another machine I do:

mongo -u admin -p adminpassword host/collection

The response I get is:

MongoDB shell version: 2.6.10 connecting to: host/collection 2019-07-12T06:20:36.336+0000 Error: 2 { ok: 0.0, errmsg: "Auth mechanism not specified", code: 2, codeName: "BadValue" } at src/mongo/shell/db.js:1287 exception: login failed

Now, I suppose this is an issue with different versions but what I'm really after is to remote connect from a node script and that's failing as well but the only message is: "MongoError: Authentication failed."

Does anyone know a solution?

2

2 Answers

5
votes

Ran into the same issue when using an old Mongo shell version (2.x/3.x) with a 4.0+ server. Upgrading the Mongo shell to 4.0.6+ seems to have resolved the issue.

My guess is the protocol to authenticate and specifying auth mechanisms has changed in newer server versions.

2
votes

Maybe is because you've tried to connect with admin user on a different collection than admin.

Try mongo -u ADMIN_USERNAME -p ADMIN_PASSWORD HOST_IP/admin