Mongo DB: Authentication failed - mongodb

I have 2 problems. First I can't login into my MongoDB. I tried this way: Can't create backup mongodump with --db. Authentication failed but no succsess. I've tried differnt passwords and user, but I can't log in. My Mongo Server runs on an Debian 8 Server. For Uninstall and install, I used this tutorial: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/ . I start the debian new after every uninstall.
Can I remove the password. In the conf data, I comment auth = true. I hope you can help me.
I get this message
MongoDB shell version: 3.2.7
connecting to: 127.0.0.1:27017/test
2016-06-29T12:30:01.079+0000 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1441:20
#(auth):6:1
#(auth):1:2
exception: login failed

No authentication by default on mongo that might have to do with system privileges.

Related

Mongo Shell/Compass won't connect to mongodb container

I'm using Docker (running on WSL) and I have a MongoDB container running. Using mongo shell on my host I can connect to the instance, but I can't authenticate. I also get an authentication error when I try to go through MongoDB Compass, below is the error I keep getting. I've installed saslprep globally via npm on my host machine, but that didn't fix the problem either. Any help would be greatly appreciated!
> db.auth('admin-root', 'test')
Warning: no saslprep library specified. Passwords will not be sanitized
MongoError: Authentication failed.

mongodb: Auth mechanism not specified

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?
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.
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

MongoDB won't connect on Ubuntu 14.04

I am trying to install MongoDB on Ubuntu 14.04 LTS. I am following the article at the link below:
https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-ubuntu/
Everything is fine, and my log file shows the following line:
2016-12-18T20:47:19.476+0000 I NETWORK [thread1] waiting for connections on port 27017
I also get the following status when i run the following command:
bitnami#ip-172-31-58-13:service mongod status
bitnami#ip-172-31-58-13:mongod start/running, process 15587
however, as soon as i try to connect to mongo, I run into an error, which I simply cannot seem to resolve.
Command:
bitnami#ip-172-31-58-13:/var/log/mongodb$ mongo
Output:
MongoDB shell version: 3.0.7
connecting to: /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017/test
2016-12-19T00:08:48.809+0000 W NETWORK Failed to connect to /opt/bitnami/mongodb/tmp/mongodb-27017.sock:0, reason: errno:2 No such file or directory
2016-12-19T00:08:48.810+0000 E QUERY Error: couldn't connect to server /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017 (/opt/bitnami/mongodb/tmp/mongodb-27017.sock), connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
exception: connect failed
bitnami#ip-172-31-58-13:/var/log/mongodb$
I have tried everything on the internet (gone through about 50+ articles) but nothing seems to work - changing the .lock file, updating the permissions, even uninstalled and re-installed mongodb 2 times and so on.
I noticed that the mongodb-27017.sock is placed under /tmp rather than /opt/bitnami/mongodb/tmp/ but I am not sure if that is a problem?
Please help me in resolving this issue.
Thank you

MongoDB Client Access Control: SCRAM-SHA-1 authentication failed, storedKey mismatch

I'm trying to activate user authorization on my local Mongo installation, but authentication keeps on failing. What can be the problem? Am I missing something?
I followed the steps outlined in "Installing on Windows" and "Enable Client Access Control":
1) Added a user
>mongo admin
MongoDB shell version: 3.2.7
connecting to: admin
> db.createUser({createUser:"admin",pwd:"admin",roles:["root"]})
Successfully added user: { "createUser" : "admin", "roles" : [ "root" ] }
>
2) Enabled Client Access Control in mongod.cfg:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
security:
authorization: enabled
3) Restarted mongod
4) Now logging in with the "right" credentials (the ones I just specified) always fails:
>mongo admin -u admin -p admin
MongoDB shell version: 3.2.7
connecting to: admin
2016-06-14T12:25:02.376+0200 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow#src/mongo/shell/db.js:1441:20
#(auth):6:1
#(auth):1:2
exception: login failed
The error in the logfile is: SCRAM-SHA-1 authentication failed for admin on admin from client 127.0.0.1 ; AuthenticationFailed: SCRAM-SHA-1 authentication failed, storedKey mismatch
Platform is Windows 10 x64, if that matters.
MongoDB 64-bit 3.2.7 with OpenSSL.
As per the documentation, the object passed to createUser should contain a user property (along with the others):
db.createUser({ user : "admin", pwd : "admin", roles : ["root"] })
^^^^ not `createUser`
Probably you're trying to recreate the database with new login and/or password. So, you need to exclude the "/db" folder. The database path's in the docker-compose.yml file. e.g.: "volumes: - ./db:/data/db".
If someone came here with the error message, this may help:
MongoDB cannot handle several symbols;
Restrictions on Database Names for Windows
For MongoDB deployments running on Windows, database names cannot contain any of the following characters:
/\. "$*<>:|?
Also database names cannot contain the null character.
Restrictions on Database Names for Unix and Linux Systems
For MongoDB deployments running on Unix and Linux systems, database names cannot contain any of the following characters:
/\. "$
https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
I stuck on the error 'Authentication failed' with mongoengine as well as pymongo.
Please change your password when containing the symbols.
I believe the password you entered on db.createUser doesn't match the one you entered when prompting Enter password in the mongo console. You can try to remove the user: db.dropUser('userName') and recreate the user. Make sure you remember the correct password.

Unable to connect to MongoLab exception: login failed

I try deploy my app Node.js + MongoDB.
I deployed my app on Heroku. Added add-ons Mongolab to app.
Opened my data base and create new user name: dima; password: *** (Add database user).
Then I try to connect to the DB:
My console:
mongo ds039135.mongolab.com:39135/heroku_xkbthxdx -u dima -p ***
MongoDB shell version: 2.4.9
connecting to: ds039135.mongolab.com:39135/heroku_xkbthxdx
Fri Feb 19 19:26:50.181 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:228
exception: login failed
What is missing in this? Thanks!
Your mongo shell version is 2.4.9. Currently all MongoLab Sandbox databases are version 3.
Upgrade your mongo shell to 3.x.y - preferably matching major release versions between client and server, MongoDB can be sensitive to major version discrepancies. Eg: Use 3.0.x shell with 3.0.x server, 2.6.x shell with 2.6.x server, etc.
Edit - adding the "why": Starting with 3.0, the default authentication mechanism is SCRAM-SHA-1, which the 2.4 mongo shell does not support, hence the failed authentication.
And then, if you have any problem with your user/pass, you can get your database username and password with:
heroku config | grep MONGODB_URI
The response is in the form of:
MONGOLAB_URI: mongodb://username:password#mlab.com:12345/db