Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't login to Mongo by shell

Tags:

mongodb

We're working on remote MongoDB base through VPN. On my local machine are working three client instances: the NodeJS server, the Compass Community instance and the mongo shell (or mongoexport).

The same URL of the form mongodb://user:pass@ip:port is used in all three cases, and both the Node.js and the Compass work just fine. Problems begin to rise when I use the Windows PowerShell and call mongo from it:

MongoDB shell version v3.6.5
Enter password:
connecting to: mongodb://{ip}:{port}/
MongoDB server version: 3.6.4
2018-06-27T18:02:00.031+0700 E QUERY    [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20
@(auth):6:1
@(auth):1:2
exception: login failed

where ip and port are here placeholders for real values. We haven't got access to the Mongo config, so is there anything I can do to connect using the shell?

like image 955
Cerberus Avatar asked Sep 02 '25 09:09

Cerberus


1 Answers

It turned out to be possible to connect using explicitly stated authentication database. I.e., the following lines does work:

mongo --host mongodb://user:pass@ip:port/ --authenticationDatabase admin
mongoexport --host mongodb://user:pass@ip:port/ --authenticationDatabase admin --db db --collection collection -o ./file.json
like image 196
Cerberus Avatar answered Sep 04 '25 23:09

Cerberus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!