Authentication failed when using mongo to connect mlab.com - mongodb

I have a account on mlab.com.
mlab-hosted deployment is running MongoDB 3.0.
I install MongoDB 3.0.10 in my computer.
I connect to mlab.com using this command:
mongo ds019480.mlab.com:<port>/<database> -u <username> -p <password>
But I get error message:
MongoDB shell version: 3.0.10-4-gbd56c2f
connecting to: ds019480.mlab.com:19480/larry-database
2016-04-08T08:45:27.101+0800 E QUERY Error: 18 Authentication failed.
at DB._authOrThrow (src/mongo/shell/db.js:1271:32)
at (auth):6:8
at (auth):7:2 at src/mongo/shell/db.js:1271
exception: login failed
How do I connect to mlab.com successfully?

remove any signs/symbols from your password. in particular '!' and '$'.

Aside from the common mistake of using your Heroku or mLabs username/password, another one may be using "double quotes".
mongo ds012345.mlab.com:<port>/<database> -u "username" -p "password"
exception: login failed
mongo ds012345.mlab.com:<port>/<database> -u 'username' -p 'password'
rs-ds012345:PRIMARY>
What’s the Difference Between Single and Double Quotes in the Bash Shell?
Conclusion: All characters within single quotes are interpreted as a string character.

Related

error in connection mongodb atlas to shell

mongo "mongodb+srv://sandbox-hoj54.mongodb.net/test" --authenticationDatabase admin --username m001-student --password m001-mongodb-basics
2020-06-19T14:18:02.553+0530 E QUERY [js] uncaught exception: SyntaxError: unexpected token: string literal :
#(shell):1:6
I think the problem is that you are running this command:
mongo "mongodb+srv://cluster0-jxrfu.mongodb.net/<dbname>" --username <password> on the MongoDB shell you downloaded in your <your mongo shell's download directory>/bin directory.
Instead, Open up a new command line and run the command. It worked for me.
There are two options to connect to db. Connect with the mongo shell or connect your application. It seems that you are trying to connect by the shell. You can see your connection string in the window:
MongoDB Atlas Panel > Clusters > 'Connect' button.
Of course you have to replace <dbname> and <password> as in the description.

Passing MongoDB user password in newline for Mongodump command using bash script

I am trying to backup a MongoDB instance that has authentication enabled but i get this error:
$> mongodump --username=admin --password=******* --authenticationDatabase=admin --db=ixpay --collection=blacklist --out=.
2020-06-02T21:39:39.086+0000 Failed: can't create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-256": (AuthenticationFailed) Authentication failed.
I am attempting this data dump using a bash script but i noticed that if i run the command directly on my terminal without the --password flag it works but then Mongodump shell will prompt for password like so:
$ mongodump --username=admin --authenticationDatabase=admin --db=ixpay --collection=blacklist --out=.
Enter password:
How do i write the mongodump command in bash, so that i can interactively(but quietly) pass the password to the Mongodump command when i execute the script?

How to connect to MongoDB on mLab through mongo shell?

I'm trying to connect to my database cluster on mLab through mongo shell using the commands as mentioned by the service providers but I keep getting the same error mentioning missing ";" statement. I can access the same database through mongoose client without any problem.
Any clue where I am messing up:
mongo ds117956.mlab.com:17956/image_search -u <dbuser> -p <dbpassword>
2017-11-29T03:04:33.139+0530 E QUERY [thread1] SyntaxError: missing ; before statement #(shell):1:6
you need to run from mongodb/bin
and then enter the following command: mongo ds117956.mlab.com:17956/image_search -u -p
not from mongo itself
mongo ds117956.mlab.com:17956/image_search -u -p

s3cmd pipe mongodb 3.0.2 SASL auth failed

Does anybody experience an issue with s3cmd and mongoimport after having upgraded to mongodb 3.0.2? I am receiving the SCRAM-SHA1 / SASL error but have no clue how I can fix this? The connection from and to s3 is still unaffected and working properly.
I was untill recently successfully using s3cmd to pipe the output from mongodb 2.6:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection
which is now returning:
"Failed: error connecting to db server: server returned error on SASL
authentication step: Authentication failed."
Thanks in advance
Try using the --authenticationDatabase parameter to direct the mongoimport tool to the database that holds the user’s credentials. Currently it fails to authenticate since it can't find the location of those credentials.
The full command should look something like this:
s3cmd get s3://filename - | mongoimport -d testdb -c testcollection -u <user_name> -p <password> --authenticationDatabase admin
This is all true to version 2.4 and up of the mongoimport tool, so make sure you have an updated version.

MongoDB shell command line authentication fails

I set up replica set with authentication. I used this tutorial. I set up keyfile, admin user and other users. It all works fine - anonymous access is disabled and I can login
$ mongo
MongoDB shell version: 2.6.1
connecting to: test
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
rs0:PRIMARY> use admin
switched to db admin
rs0:PRIMARY> db.auth("USERNAME","PASSWORD")
1
rs0:PRIMARY>
using credentials of users I created.
But I can't login from command line
$ mongo -u 'USERNAME' -p 'PASSWORD'
MongoDB shell version: 2.6.1
connecting to: test
2014-05-18T14:23:47.324+0200 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
using the same credentials. I haven't find anything helpful in the documentation or here on SO.
The in-shell authentication performed in your example is against the admin database. The command line posted above does not specify a database and is therefore authenticating against the default database which is test. Try this instead to authenticate via command line against the admin db:
mongo admin -u 'USERNAME' -p 'PASSWORD'
if the server is not on the local host then you can use this:
mongo your_host_name:your_port/admin -u 'USERNAME' -p 'PASSWORD'
Perhaps different now because of an update since this question was originally answered, but authentication only succeeds when wrapping username/password in double quotes.
e.g.,
mongo admin -u "myName" -p "myPassword"