I'm trying to connect remotely on a mongodb server throw my local machine, but i'm having some issues.
On the remote server i modified the 'mongod.cfg' file and i changed the bindIp from 127.0.0.1 to 0.0.0.0 to allow access. In the same file i changed the security by adding Authentication: 'enabled'.
I created an admin user:
> use admin > db.createUser({user: "root", pwd: "root", roles:["root"]}) I started mongodb with --auth flag
> mongod --auth --port 27017 Once the server was up, i connect to it as administrator
mongo 127.0.0.1:27017 -u "root" -p "root" --authenticationDatabase "admin" Once i was connected, i created a normal user
> use base > db.createUser({user: "base", pwd: "base", roles:["dbOwner"]}) Then i disconnected from mongo shell and reconnected with new user credentials
> mongo <127.0.0.1:27017>/base -u "base" -p "base" It worked properly on the remote server.
On the local machine i tried the same command on my local machine and it failed
> mongo 127.0.0.1:27017/base -u "base" -p "base" [js] Error: Authentication failed. : connect@src/mongo/shell/mongo.js:344:17 @(connect):2:6 exception: connect failed
tasklist | findstr mongodto get the pid of the mongod thennetstat -ano | findstr PIDto get the ip on which mongod is running. Then use this IP as suggested earlier.